要使用这么大的功能 ConvertAll()
,我必须的IList
转换为列表
,这是痛苦的。
To use such great function as ConvertAll()
, I have to convert IList
to List
, it's painful.
推荐答案
注意名单,其中;>
是的IList&LT的实现;>
与实际存储,也就是说,它拥有在后台的数组。在一般情况下,一个的IList<>
可以是别的东西的代理。在db4o中和LINQ to SQL,你的的IList<>
可以'点查询,即访问列表将触发数据库操作。
Note that List<>
is an implementation of IList<>
with actual storage, i.e. it holds an array in the background. In general, an IList<>
can be a proxy to something else. In db4o and linq to sql, your IList<>
could 'point to a query', i.e. accessing the list will trigger a database operation.
这样,您就可以执行 myList.Skip(600)。取(20);
来进行分页,只有在这一步将实际的查询执行。 A 名单,其中;&GT;
一百万个条目将是巨大的,而有可能是的IList&LT;&GT;
s表示有一个巨大的计数
,但不要吃显著的存储量 - 只要你不访问的元素
This way, you can perform myList.Skip(600).Take(20);
to perform pagination and only in this step will the actual query be executed. A List<>
containing a million entries will be huge, while there may be IList<>
s that have a huge Count
, but don't eat a significant amount of memory - as long as you don't access the elements.
ConvertAll
将要求每一个对象实例化所以它是一个代价高昂的操作。因此,最好是使操作显性和迫使你检索接口的特定实现。显然,转换需要进行反正实例化的所有对象,所以没有好处做它懒洋洋地。
ConvertAll
will require each and every object be instantiated so it is a costly operation. Thus, it is better to make the operation explicit and force you to retrieve a specific implementation of the interface. Obviously, conversion requires all objects to be instantiated anyway, so there's no benefit in doing it lazily.
相关推荐
最新文章