Tag: tolist

返回LINQ结果时何时调用ToList的经验法则

我正在寻找在IEnumerables上调用ToList/ToArray/MemoizeAll(Rx)的经验法则,而不是在返回IEnumerable时返回查询本身。 通常我发现最好只返回查询并让调用者决定是否需要列表,但有时它会因为linq的惰性而回来并咬你。 我想收集指南,例如: 调用ToList如果: 你创建新的对象(例如在选择中) 您的查询中有副作用 否则,返回查询

Dictonary to ToList ArithmeticFlowException

在负载测试期间面临exception,算术导致溢出。 public static IDictionary<string, ISet> SereverConnections = new ConcurrentDictionary<string, ISet>(); public static IList GetUserConnections(string username) { //Key must not be null in any case return null if someone send and empty username if (string.IsNullOrEmpty(username)) return null; ISet connections; Global.SereverConnections.TryGetValue(username, out connections); //this will make the copy of the //return (connections != null ? connections.ToList() ?? […]

entity .ToList()生成一个System.OutOfMemoryException

我有一张五十万行的表。 我需要更新每一行,但ToList()失败: List allContacts = objDatabase.Contacts.ToList(); 我每次都得到一个System.OutOfMemoryException。 有没有解决的办法? 我已经有了App.Config的解决方法,但仍然没有去: 我是64位机器,内存为8GB

foreach只执行一次查询吗?

我有一个项目列表和LINQ查询。 现在,使用LINQ的延迟执行,后续的foreach循环是否只执行一次查询或循环中的每次转弯? 给出这个例子(取自LINQ查询简介(C#),在MSDN上 ) // The Three Parts of a LINQ Query: // 1. Data source. int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 }; // 2. Query creation. // numQuery is an IEnumerable var numQuery = from num in numbers where (num % 2) == 0 select num; // […]