2

PLinq を使用している場合、各 PLINQ の項目のコレクションを Shared Collection に追加する必要があります。現在、BlockingCollection> を使用しています。同様の機能を実行する C# で利用可能な他のデータ構造があります。特定のキーの個別の値を保持するには、このコレクションが必要です。

4

1 に答える 1

1

IComparer を使用して List> を作成することで、問題を解決しました。

これが Comparer public class KeyValueComparer です: IEqualityComparer> { public bool Equals(KeyValuePair x, KeyValuePair y) { return (x.Key == y.Key && x.Value == y.Value); }

    public int GetHashCode(KeyValuePair<string, string> referenceObj)
    {
        //Check whether the object is null 
        if (Object.ReferenceEquals(referenceObj, null)) return 0;

        //Get hash code for the Name field if it is not null. 
        int hashProductName = referenceObj.Equals(default(KeyValuePair<string, string>)) ? 0 : referenceObj.Value.GetHashCode();

        return hashProductName;
    }
}

コレクション var collection= CollectionWithKVPair.Distinct(new KeyValueComparer()); を呼び出してみます。

これにより、複数の同じキーで異なる値を持つリストの問題が解決されます。

于 2013-05-03T15:52:56.567 に答える