Generic Dictionary to List<string[]>

  • Thread starter Thread starter Vanitha Loganathan
  • Start date Start date
V

Vanitha Loganathan

Guest
I have a generic dictionary, which has id,value,type,section parameters as get; set; in a class, I want to add these values into the List<string[]>. right now I declared one more string array and added those values into the List<string[]> but its overwriting the existing values in the list, please see the below code:-

public class Parameters
{

public int Id { get; set; }
public string Key { get; set; }
public object Value { get; set; }

public string Type { get; set; }
public string Section { get; set; }
}
Dictionary<string, Parameters> _Data;
List<string[]> _updateList = new List<string[]>();
_Data = new Dictionary<string, Parameters>();
_Data = DataFromFile(file); --> this method will fetch the below multiple items
_Data dictionary will have Key:-( _ROOT_COUNT), Value :- (Key -COUNT, Id-123,value-1,Type-L,Section-_ROOT)
also this dictionary has 4 count , i mean totally 16 value items will be there.
I need to assign in List<string[]>. Please let me know best way to assign the string[] List

Current approach is
string[] _updateConfigSet = new string[4];
_updateConfigSet = new string[4];
for (int index = 0; index < _Data.Count; index++)
{
var item = _Data.ElementAt(index);
var itemKey = item.Key;
var itemValue = item.Value;
_updateConfigSet[0] = itemValue.Section.ToString();
_updateConfigSet[1] = itemValue.Key.ToString();
_updateConfigSet[2] = itemValue.Value.ToString();
_updateConfigSet[3] = itemValue.Type.ToString();
_updateList.Insert(index, _updateConfigSet);
}

But the list is not updated properly only the last values are in the list, i mean all the 4 items are duplicate values. Please let me know a good approach. Waiting for the replies. Thanks in Advance.

Continue reading...
 
Back
Top