c# - 键值对数据结构的最佳实现?

标签 c# data-structures collections

所以最近我一直在研究 C#,所有的泛型集合让我有点困惑。假设我想表示一个数据结构,其中树的头部是一个键值对,然后在它下面有一个可选的键值对列表(但级别不超过这些)。这样合适吗?

public class TokenTree
{
    public TokenTree()
    {
        /* I must admit to not fully understanding this,
         * I got it from msdn. As far as I can tell, IDictionary is an
         * interface, and Dictionary is the default implementation of
         * that interface, right?
         */
        SubPairs = new Dictionary<string, string>();
    }

    public string Key;
    public string Value;
    public IDictionary<string, string> SubPairs;
}

它实际上只是一个简单的分流器,用于传递数据。

最佳答案

有一个实际的数据类型叫做KeyValuePair,像这样使用

KeyValuePair<string, string> myKeyValuePair = new KeyValuePair<string,string>("defaultkey", "defaultvalue");

关于c# - 键值对数据结构的最佳实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8800/

相关文章:

c# - 将 Eorzea DateTime 值转换为地球时间

java - Collections.sort(...) 是如何工作的?

c# - 如何在 C# 中生成 8 位唯一和随机数

c# - 使用 TextWriter c# 清除文本文件的内容

c# - The Short Date ("d") Format Specifier does not print year with 4 digits in .NET Core on MacOS

python - 元组列表的自定义排序

ios - 混淆线程和队列之间的技术术语

algorithm - 有效检测与给定点对应的矩形区域( map )

Servlet 中的 java.util.ConcurrentModificationException

java - LinkedHashSet javadoc 中的错误?