Setting List items in C# without automatic setter/getter

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

    You are trying to use the set{} method as the Add method, which it isn't. set is used to change the entire collection whereas an Add method would add an item to the collection. what has been stated in other answers is correct... if you really want the = operator to add to the collection rather than assign a new collection, you can use AddRange() but for clarity sake, you should be overriding the = operator if that is the case.

提交回复
热议问题