gpt4 book ai didi

c# - .NET 字典作为属性

转载 作者:IT王子 更新时间:2023-10-29 04:17:37 28 4
gpt4 key购买 nike

谁能指出一些 C# 代码示例或提供一些代码,其中字典已用作类的属性。

到目前为止,我看到的示例并未涵盖所有方面,即如何将字典声明为属性、添加、删除和检索字典中的元素。

最佳答案

这是一个简单的例子

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

关于c# - .NET 字典作为属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/980991/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com