How to write a getter and setter for a Dictionary?

前端 未结 6 1686
暗喜
暗喜 2020-12-17 09:09

How do you define a getter and setter for complex data types such as a dictionary?

public Dictionary Users
{
    get
    {
        retu         


        
6条回答
  •  無奈伤痛
    2020-12-17 10:12

    It is possible to do so with the setter but highly unrecommended, and is completely impossible with the getter as it takes no parameter to determine what to get.

    For the setter you would have to pass a Dictionary with a single pair but it goes against what you would expect the getter/setter to usually do and completely stops you setting the entire Dictionary.

    A much better way is to use a pair of methods which you can name Get and Set if you so desire.

提交回复
热议问题