.NET词典作为物业 [英] .NET Dictionary as a Property
本文介绍了.NET词典作为物业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人能指出我出去一些C#code例子或提供一些code,其中一个字典已被用作一类的属性。
Can someone point me out to some C# code examples or provide some code, where a Dictionary has been used as a property for a Class.
我迄今所看到的例子并不包括即如何声明的字典作为物业,添加,删除和检索字典中元素的方方面面。
The examples I have seen so far don't cover all the aspects viz how to declare the dictionary as property, add, remove, and retrieve the elements from the dictionary.
推荐答案
下面是一个简单的例子
class Example {
private Dictionary<int,string> _map;
public Dictionary<int,string> Map { get { return _map; } }
public Example() { _map = new Dictionary<int,string>(); }
}
一些用例
var e = new Example();
e.Map[42] = "The Answer";
这篇关于.NET词典作为物业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文