.NET Dictionary as a Property

后端 未结 8 489
-上瘾入骨i
-上瘾入骨i 2021-02-02 08:30

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\'

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-02 09:17

    Here's a quick example

    class Example {
      private Dictionary _map;
      public Dictionary Map { get { return _map; } }
      public Example() { _map = new Dictionary(); }
    }
    

    Some use cases

    var e = new Example();
    e.Map[42] = "The Answer";
    

提交回复
热议问题