c# - 如何在 C# 中将字典初始化为 (key, value, value) 对

标签 c# .net dictionary

我想将值存储为键、值、值对。我的数据类型

Key -> int & both values -> ulong,

如何初始化和获取此类字典的值。我正在使用 VS-2005。

如果我使用类或结构,那么我该如何获取值。

最佳答案

创建一个结构来存储你的值:

struct ValuePair
{
    public ulong Value1;
    public ulong Value2;
}

字典初始化:

Dictionary<int, ValuePair> dictionary = new Dictionary<int, ValuePair>();

如果您使用 int 作为键,也许 List 就足够了?

列表:

List<ValuePair> list = new List<ValuePair>();

ValuePair 可以添加到 list 中,如下所示:

list.Add(new ValuePair { Value1 = 1, Value2 = 2 });

关于c# - 如何在 C# 中将字典初始化为 (key, value, value) 对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1845741/

相关文章:

c# - 在编译时强制进行狭窄的隐式强制转换

c# - 如果数据未按给定偏移量对齐,为什么 BitConverter.ToInt32 一次读取一个字节?

c# - 过滤列表以删除非数字项

c# - GnuTLS 错误 -110 : The TLS connection was non-properly terminated

c# - 将标签文本显示为警告消息并在几秒钟后隐藏?

python - Flask 中的 JSON 数据是字符串还是字典?

javascript - javascript中的关联数组使用对/元组作为多值键/索引

c# - 将 XSD 1.1 模式转换为 c# 类

c# - 将 FileSavePicker 与 MessageDialog 的 IUICommand 事件一起使用

arrays - 如何循环像forEach这样的不可变列表?