为什么这会产生一个空集?
Object[] types = {23, 234, "hello", "test", true, 23};
var newTypes = types.Select(x => x.GetType().Name)
.Where(x => x.GetType().Name.Equals("Int32"))
.OrderBy(x => x);
newTypes.Dump();
最佳答案
当您进行选择时,您会得到一个 IEnumerable<String>
.然后,您将获取列表中每个字符串的类型(全是“String”),并在不等于“Int32”(即整个列表)的地方过滤掉它们。因此...列表是空的。
关于c# - 为什么 .Equals 在此 LINQ 示例中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1675162/