相关疑难解决方法(0)

IStructuralEquatable和IStructuralComparable解决了什么问题?

我注意到这两个接口,以及几个相关的类,已经在.NET 4中添加了.它们对我来说似乎有点多余; 我已经阅读了几个关于它们的博客,但我仍然无法弄清楚它们在.NET 4之前解决了哪些棘手问题.

什么是使用IStructuralEquatableIStructuralComparable

.net equality icomparable iequalitycomparer

55
推荐指数
4
解决办法
7842
查看次数

字典是否可以将数组作为键?

面对字典中的问题.数组是否可以成为价值的关键???

Dictionary<string[], int> di = new Dictionary<string[], int>();
di.Add(new string[]
{
    "1","2"
}, 1);

di.Add(new string[]
{
    "2","3"
}, 2);

MessageBox.Show(di[new string[] { "2", "3" }].ToString()); // Here KeyNotFoundException occurred.
Run Code Online (Sandbox Code Playgroud)

为什么例外?

c# dictionary

3
推荐指数
1
解决办法
488
查看次数

声明内部字典比较器C#

我有一本字典如下

Dictionary<ulong, Dictionary<byte[], byte[]>> Info;
Run Code Online (Sandbox Code Playgroud)

内部字典将byte []数组作为键.

我无法理解如何声明Info字典的构造函数.对于我所拥有的内部键比较ByteArrayComparer,

  public class ByteArrayComparer : IEqualityComparer<byte[]> 
    {
        public bool Equals(byte[] left, byte[] right)
        {
            if (left == null || right == null)
            {
                return left == right;
            }
            if (left.Length != right.Length)
            {
                return false;
            }
            for (int i = 0; i < left.Length; i++)
            {
                if (left[i] != right[i])
                {
                    return false;
                }
            }
            return true;
        }
        public int GetHashCode(byte[] key)
        {
            if (key == null)
                throw new …
Run Code Online (Sandbox Code Playgroud)

c# dictionary

0
推荐指数
1
解决办法
844
查看次数

标签 统计

c# ×2

dictionary ×2

.net ×1

equality ×1

icomparable ×1

iequalitycomparer ×1