Use of LINQ and ArrayList

前端 未结 3 1077
借酒劲吻你
借酒劲吻你 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:12

    The only effect the use of AsQueryable() has here is to make the static type of the result of the query is IQueryable. For all intents and purposes, this is really useless on an object.

    You only really need:

    var myStrings = list.Cast();
    

    without the AsQueryable(). Then the type of the result is just IEnumerable.

    Or better yet, to get a strongly typed List:

    var myStrings = list.Cast().ToList();
    

提交回复
热议问题