How to write a getter and setter for a Dictionary?

前端 未结 6 1689
暗喜
暗喜 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:03

    It looks like you want an "named indexer". Here's (my) one way to accomplish that using C#.

    My approach exposes a property that returns an object (with a default indexer) which will perform the indexing into the appropriate field given the lambdas to do it.

    There are reasons you may or not want to use this method, but I'll leave that to you. :)

提交回复
热议问题