int[] arr = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
List<Person> listPerson = new List<Person>()
{
new Person(){Name=”张三”,Age=28},
new Person(){Name=”李四”,Age=33},
new Person(){Name=”赵四”,Age=32},
new Person(){Name=”王小二”,Age=29}
};
var queryIntArray = from n in arr select n; //问题 本人想 queryIntArray [2] 获取2 语法有问题
IEnumerable<Person> enumerablePerson = from person in listPerson select person //问题,本人想不迭代,通过下标或key访问结果集中的某一个元素对象
List<Person> listPerson = new List<Person>()
{
new Person(){Name=”张三”,Age=28},
new Person(){Name=”李四”,Age=33},
new Person(){Name=”赵四”,Age=32},
new Person(){Name=”王小二”,Age=29}
};
var queryIntArray = from n in arr select n; //问题 本人想 queryIntArray [2] 获取2 语法有问题
IEnumerable<Person> enumerablePerson = from person in listPerson select person //问题,本人想不迭代,通过下标或key访问结果集中的某一个元素对象
解决方案
25
int[] arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var queryIntArray = (from n in arr select n).ToArray(); Console.WriteLine(queryIntArray[2]); List<Person> listPerson = new List<Person>() { new Person(){Name="张三",Age=28}, new Person(){Name="李四",Age=33}, new Person(){Name="赵四",Age=32}, new Person(){Name="王小二",Age=29} }; var enumerablePerson = (from person in listPerson select person).ToList(); Console.WriteLine("{0} {1}", enumerablePerson[2].Name, enumerablePerson[2].Age);
10
ToList
5
tolist toarray都可以
5
IEnumerable转List/Array后再操作