例如,我有这样的代码:如何打破源收集和LINQ结果之间的联系
IEnumerable<RSuspectOperationCode> distinctCodes = this.Distinct(); // "this" is some collection
this.Clear()
distinctCodes.Count();
由于LINQ的延迟执行查询 - 伯爵给我们0我有意思 - 有没有办法通过就地结果计算并打破源和结果集合之间的链接,获得一个独特的集合,清除源集合将不会影响结果集合?
我的解决方法:
List<RSuspectOperationCode> distinctCodes = new List<RSuspectOperationCode>();
distinctCodes.AddRange(this.Distinct(comparer));
this.Clear();
distinctCodes.Count();
但是,我不知道,有没有更优雅/短呢?
对不起,通过内存类型代码,mistakened的 – 2014-08-31 07:55:39
可能重复[强制LINQ到不耽误执行] (http://stackoverflow.com/questions/1064043/force-linq-to-not-delay-execution) – 2014-08-31 07:58:05