This is not an error, but a consequence of how the initializer { ... } syntax works in C #.
This syntax is available for any type of collection that has the Add() method. And all he does is replace the sequence in braces with the sequence of calls to the Add() method.
In your example, you first initialize the value with the first three elements in the constructor. Then, later, when you assign the property { 4, 5, 6 } property that calls Add() again with these values.
If you want to delete the previous contents, you need to assign a new operator, for example:
var listTest = new ListTest() { MyList = new List<int> {4,5,6} };
By including the new operator, you get both the whole new object and the Add() values.
source share