如何初始化字典作为(键,值,值)在C#中对 [英] how to initialize dictionary as (key,value,value) pair in C#

查看:167
本文介绍了如何初始化字典作为(键,值,值)在C#中对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要值存储为键,值,值对。我的数据类型

I want to store values as key,value,value pair. My data is of type

Key -> int & both values -> ulong,



如何初始化和放大器;取这样的字典值。我使用的VS-2005。

How to initialize & fetch values of such dictionary. I am using VS-2005.

如果我使用一个类或结构,然后我如何获取值。

If i use a class or struct then how do i fetch the values.

推荐答案

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

Create a structure to store your values:

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

词典初始化:

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



也许列表就足够了,如果你使用INT为重点?

Maybe List is enough, if you use int as key?

清单:

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



ValuePair <​​/ code>可被添加到列表如下:

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

这篇关于如何初始化字典作为(键,值,值)在C#中对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆