声明内部字典比较器C#
我有一本字典如下声明内部字典比较器C#,c#,dictionary,C#,Dictionary,我有一本字典如下 Dictionary<ulong, Dictionary<byte[], byte[]>> Info; 这是我从某处捡到的 请告知比较器的规范不会直接作为信息初始化的一部分,而是在您创建一个值放入外部字典时。例如: // It's stateless, so let's just use one of them. private static readonly IEqualityComparer<byte[]> ByteArrayCompa
Dictionary<ulong, Dictionary<byte[], byte[]>> Info;
这是我从某处捡到的
请告知比较器的规范不会直接作为
信息
初始化的一部分,而是在您创建一个值放入外部字典时。例如:
// It's stateless, so let's just use one of them.
private static readonly IEqualityComparer<byte[]> ByteArrayComparerInstance
= new ByteArrayComparer();
Dictionary<ulong, Dictionary<byte[], byte[]>> Info
= new Dictionary<ulong, Dictionary<byte[], byte[]>();
....
...
Dictionary<byte[], byte[]> valueMap;
if (!Info.TryGetValue(key, out valueMap))
{
valueMap = new Dictionary<byte[], byte[]>(ByteArrayComparerInstance);
Info[key] = valueMap;
}
...
//它是无状态的,所以让我们使用其中一个。
私有静态只读IEQualityComparerByteArrayComparerInstance
=新的ByteArrayComparer();
字典信息
=新建词典创建时,您的Info
中没有任何词典,因此您无法在该步骤中真正定义comparere。您必须对添加到Info
对象中的每个项目执行此操作。@Piotr,在编写字典中的提取代码时,可能会节省一些手动代码步骤?
// It's stateless, so let's just use one of them.
private static readonly IEqualityComparer<byte[]> ByteArrayComparerInstance
= new ByteArrayComparer();
Dictionary<ulong, Dictionary<byte[], byte[]>> Info
= new Dictionary<ulong, Dictionary<byte[], byte[]>();
....
...
Dictionary<byte[], byte[]> valueMap;
if (!Info.TryGetValue(key, out valueMap))
{
valueMap = new Dictionary<byte[], byte[]>(ByteArrayComparerInstance);
Info[key] = valueMap;
}
...