Setting List items in C# without automatic setter/getter

后端 未结 6 2058
难免孤独
难免孤独 2021-01-16 09:46

I\'m trying to make a manual setter/getter method in C#, but i\'m getting the following error from the \"set\"-line: Error: The best overloaded method match for \'System.Col

6条回答
  •  攒了一身酷
    2021-01-16 10:25

    Your code should look like this.

    private var packages = new List();    
    
    public List Packages
    {
        set { packages = value; }
        get { return packages; }
    }
    

    If you're trying to use the index getter/setter for some kind of passthrough:

    public int this[int key]
    {
        get
        {
            return Packages[key];
        }
        set
        {
            Packages[key] = value;
        }
    }
    

提交回复
热议问题