最佳实现键值对数据结构?

编程入门 行业动态 更新时间:2024-10-27 20:39:01
本文介绍了最佳实现键值对数据结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我最近一直在用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.

推荐答案

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

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

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

更多推荐

最佳实现键值对数据结构?

本文发布于:2023-11-30 17:58:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650990.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据结构   键值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!