bool[] trueOrFalse = new bool[] { true, false }; int[] para1 = new int[] { 1, 2, 3 }; int[] para2 = new int[] { 5, 6, 7 }; int[] para3 = new int[] { 1, 2, 3 }; int[] para4 = new int[] { 5, 7, 9 }; List test = (from a in trueOrFalse from b in para1 from c in para2 from d in para3 from e in para4 let f = c - d where c - d <= 3 select new { a, b, c, d, e, f }).AsEnumerable().ToList();
var test = (from a in trueOrFalse from b in para1 from c in para2 from d in para3 from e in para4 let f = c - d where c - d <= 3 select new { a, b, c, d, e, f }).ToList();
然后你可以这样做:
foreach (var item in test) { Console.WriteLine(item.a); // Strongly typed at compile-time }
var i=test.FirstOrDefault(); if (i==null) { // NO ITEMS IN LIST!!! // So do something else! } var type=i.GetType(); var aGetter=type.GetProperty("a"); var bGetter=type.GetProperty("b"); foreach (var item in test) { bool myA = (bool)aGetter.GetValue(item,null); int myB=(int)bGetter.GetValue(item.null); }
你可以使用reflection:
bool[] trueOrFalse = new bool[] { true, false }; int[] para1 = new int[] { 1, 2, 3 }; int[] para2 = new int[] { 5, 6, 7 }; int[] para3 = new int[] { 1, 2, 3 }; int[] para4 = new int[] { 5, 7, 9 }; List
你也可以给你的字段命名如下:
select new { aName = a, bName = b, cName = c, dName = d, gName = g, fName = f }).AsEnumerable().ToList();
然后使用:
foreach (object item in test) { Response.Write(item.GetType().GetProperty("aName").GetValue(item, null).ToString()); }