Use of LINQ and ArrayList

前端 未结 3 1080
借酒劲吻你
借酒劲吻你 2021-01-05 10:42

I\'ve recently used LINQ

In the following code:

ArrayList list = new ArrayList();
var myStrings = list.AsQueryable().Cast();

3条回答
  •  迷失自我
    2021-01-05 11:10

    You do not need the call to AsQueryable(). Queryables only make sense when a LINQ query (expressed in C#) needs to be converted to another domain language (such as SQL). In your case since you are working with LINQ to Objects (you are operating on an array list) this is not needed.

    You can call the Cast() method directly on the list instance. Another choice would be to start with a strongly-typed collection such as List.

提交回复
热议问题