查询表达式创建的对象是什么类型的?

时间:2014-02-27 06:09:58

标签: c# linq

List<int> b = new List<int>() { 12, 56, 45, 65, 4, 6 };
b.Add(125);

IEnumerable<int> c = from n in b
                     where n < 60 && n > 12
                     select n;

c是否引用?什么类型是from ... select n

2 个答案:

答案 0 :(得分:3)

c的类型为:

System.Linq.Enumerable+WhereListIterator`1[System.Int32]

您可以通过检查c.GetType();

来看到这一点

如果您希望对其进行评估并将其转化为“实际”状态。列表,您可以尝试:

IEnumerable<int> c = (from n in b where n < 60 && n > 12 select n).ToList();

答案 1 :(得分:0)

c是IEnumerable<int>类型的对象 它可能是一个List或任何其他集合。

无论如何不是参考

ps:谢谢你abatishchev

相关问题