Convert list <int> to list <List <int>>
6 answers
.
List<int> element = new List<int>();
List<List<int>> superElement = new List<List<int>> { element };
http://msdn.microsoft.com/en-gb/library/vstudio/bb384062.aspx
+5
, , , , , , , .
, , . , :
List<int> element = new List<int>();
List<List<int>> superElement = new List<List<int>>();
superElement.Add(element);
, , , , (, ) , ID . .
, , :
public class MyData
{
public int ID {get; set;}
public List<int> MyValues {get;set;}
public MyData()
{
MyValues = new List<int>();
}
}
:
List<int> element = new List<int>();
MyData data = new MyData();
data.ID = 1;
data.MyValues = element;
List<MyData> superElement = new List<MyData>();
superElement.Add(data);
:
MyData data1 = superElement.SingleOrDeafult(x => x.ID == 1);
List<int> element = data1.MyValues;
, Linq.
, :
Dictionary<int, List<int>> superElement = new Dictionary<int, List<int>>();
superElement.Add(1, element);
1 - , :
List<int> element = superElement[1];
+3