Please explain why the creation of several variables does not work this way:

public class Point { int a; int b; } Point a, b, c = new Point(); 


  • Probably because you need to try this? Point a = new Point (), b = new Point (), c = new Point (); - gecube
  • Ie it turned out that I only created the C object, and the a and b objects were not taken into account by the compiler? - fakl
  • I think that you are thinking in the right direction. But I am not an expert on C #, so it’s better to try and tell what happened :-) - gecube
  • I tried it, and it turned out as described (only the last variable was created). Thanks for the tip) - fakl

1 answer 1

Because new (memory capture operator), you use only for one object, and you cannot capture the same memory for different objects as you do!