问题描述
我最近使用过LINQ
I've recently used LINQ
在以下代码中:
ArrayList list = new ArrayList();
var myStrings = list.AsQueryable().Cast<string>();
AsQueryable
的作用是什么?我知道Cast
创建一个类型安全的集合,而ArrayList
已弃用.
What is the AsQueryable
for? I know Cast
creates a type-safe collection, and ArrayList
is deprecated.
我有一个朋友说他需要将AsQueryable
与ArrayList
结合使用.我试图了解原因,但看不到为什么需要AsQueryable
.
I've got a friend who says he needs the AsQueryable
combined with ArrayList
. I'm trying to understand why, but I can't see why AsQueryable
is needed.
他错了吗?
推荐答案
AsQueryable将用于生成一个IQueryable,如果实现了该IQueryable,则可以通过表达式树分析查询以将其重写或翻译成其他类似语言的形式例如,使用linq to sql.
AsQueryable would be used to produce an IQueryable which can then, if implemented, analyse the query via expression trees to rewrite it or translate it into some other language-like with linq to sql for example.
在这种情况下,这完全没有意义,您可以告诉您的朋友不要打扰.
In this case it is completely pointless and you can tell your friend not to bother.
这篇关于LINQ和ArrayList的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!