Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C语言中是否有用于BlockingCollection的等效数据结构<;KeyValuePair<;字符串,字符串>&燃气轮机;_C#_C# 4.0 - Fatal编程技术网

C# C语言中是否有用于BlockingCollection的等效数据结构<;KeyValuePair<;字符串,字符串>&燃气轮机;

C# C语言中是否有用于BlockingCollection的等效数据结构<;KeyValuePair<;字符串,字符串>&燃气轮机;,c#,c#-4.0,C#,C# 4.0,Im使用PLinq,我必须将每个PLinq的项目集合添加到共享集合中,目前Im使用BlockingCollection>C中是否有其他具有类似功能的数据结构可用。我需要使用此集合来保存给定键的不同值。我通过使用IComparer创建列表>,解决了我的问题 这是比较器 公共类KeyValueComparer:IEqualityComparer> { 公共布尔等于(键值对x、键值对y) { 返回(x.Key==y.Key&&x.Value==y.Value); } public int Ge

Im使用PLinq,我必须将每个PLinq的项目集合添加到共享集合中,目前Im使用BlockingCollection>C中是否有其他具有类似功能的数据结构可用。我需要使用此集合来保存给定键的不同值。

我通过使用IComparer创建列表>,解决了我的问题

这是比较器 公共类KeyValueComparer:IEqualityComparer> { 公共布尔等于(键值对x、键值对y) { 返回(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;
    }
}
public int GetHashCode(KeyValuePair referenceObj)
{
//检查对象是否为空
if(Object.ReferenceEquals(referenceObj,null))返回0;
//如果名称字段不为null,则获取其哈希代码。
int-hashProductName=referenceObj.Equals(默认值(KeyValuePair))?0:referenceObj.Value.GetHashCode();
返回hashProductName;
}
}
我试着去催收 var collection=CollectionWithKVPair.Distinct(新的KeyValueComparer())


这将解决具有多个相同键但值不同的列表的问题。

您在寻找吗?如果你能更好地解释你的要求,那就太好了“为给定的键保留不同的值”是什么意思?这是否意味着您希望能够添加具有相同键的多个项,并将这些项中的每一项视为一个不同的实体?是的,matthew,我希望存储不同的键值。我可能有多个名称相同的键,但它们的值可能不同。