Question on ASP.NET classes

Can anyone tell me the difference between

static public public static 

and

 private int _myin = 0 public int MyInt { get{ return _myInt; } private set {_myInt = value; } } 

the private part of the set is what I want to know

+4
source share
1 answer

The first 2 are no different from each other, you can order modifiers as you like, although this is more common:

 public static 

Secondly, this means that the property can only be set inside the class, but can be accessed publicly by anyone who has the link.

eg. this only works inside the class:

 MyInt = 123; 

But it works anywhere:

 int Temp = MyClass.MyInt; 

And as another example, this will not work:

 var mc = new MyClass(); mc.MyInt = 123; //this won't compile, it not a public setter 
+10
source

Source: https://habr.com/ru/post/1316606/


All Articles