键值对数据结构的最佳实现? [英] Best implementation for Key Value Pair Data Structure?

查看:35
本文介绍了键值对数据结构的最佳实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I've been poking around with C# a bit lately, and all the Generic Collections have me a little confused. Say I wanted to represent a data structure where the head of a tree was a key value pair, and then there is one optional list of key value pairs below that (but no more levels than these). Would this be suitable?

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;
}

这只是传递数据的简单分流器.

It's only really a simple shunt for passing around data.

推荐答案

有一个实际的Data Type叫做KeyValuePair,像这样使用

There is an actual Data Type called KeyValuePair, use like this

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

这篇关于键值对数据结构的最佳实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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