Currently I have a class called Field:
public class Field
{
public int Id { get; set; }
}
var listOfListOfFields = new List<List<Field>>();
var listOfFields = new List<Field>(){ new Field {id = 1}}; // in reality, data comes here.
for (int i = 0; i <= 2; i++)
{
var copyFirstList = listOfFields.ToList(); // to avoid reference thing, I still get same value
for(int j =0; j < copyFirstList.Count; j++)
{
copyFirstList[j].Id = i;
}
listOfListOfFields.Add(copyFirstList);
}
The output in the listOfListOfFields contains 2 for all the lists in id. Please suggest.