Setting List items in C# without automatic setter/getter

后端 未结 6 2112
难免孤独
难免孤独 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

    I think you have yourself a bit mixed up here.

    The type of Packages is List. When you're calling packages.Add(value);, packages is in fact, List.

    public List  Packages
    {
        get { return packages; }
        set { packages = value; }
    }
    

    This corrects the property.

    To add an item:

    Packages.Add(myPackage);
    

提交回复
热议问题