Problem with filling List

  • Thread starter Thread starter fTob98
  • Start date Start date
F

fTob98

Guest
List<List<int>> list0 = new List<List<int>>();
foreach (var x in Field)
{
list0.Clear();
foreach (var y in SeriesSet)
{
if (y.Contains(x)) list0.Add(y);
}
FSeries.Add(list0);
}

I have List<List<int>> SeriesSet and List<int> Field. My goal is to create collection (List<List<List<int>>> FSeries) that for each element x in Field holds series y from SeriesSet that each y contains x e.g.

Field = {0,1,2}

SeriesSet = {{0,1},{0,2},{1,2}}

FSeries = {{{0,1},{0,2}},{{0,1},{1,2}},{{0,2},{1,2}}}

Unfortunately, after each iteration of the first foreach loop FSeries is filled with same values for each element that has already been asigned e.g. FSeries[0] was {{0,1},{0,2}} and after second iteration FSeries[0] = {{0,1},{1,2}} and FSeries[1] = {{0,1},{1,2}}. What is wrong in my code? I thought that it would append the list to the end of FSeries and produce FSeries[0]={{0,1},{0,2}} and FSeries[1]={{0,1},{1,2}}

Continue reading...
 
Back
Top