Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
IQueryable を受け取り、別のスレッド/タスクでスレッド セーフな方法で操作 (上位 10 個の要素を取得するなど) を実行する汎用拡張メソッドを作成したいと考えています。
誰かがそれを行う正しい方法のコード例を教えてください
ありがとう
このようなもの
public static List<T> GetTopN<T>(IQueryable<T> inData, int n) { List<T> outData = new List<T>(n); lock (inData) { int i = 0; foreach (T t in inData) { if (i >= n) { return outData; } i++; outData.Add(t); } } return outData; }