Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Classes Question

Tags:

c#

asp.net

Could someone 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 set part is what I want to know

like image 404
ONYX Avatar asked Dec 28 '22 09:12

ONYX


1 Answers

The first 2 are no different, you can order the modifiers however you like, though this is more common:

public static

The second, it means that the property can only be set within the class, but can get gotten publicly, by anyone with a reference.

E.g. this only works inside the class:

MyInt = 123;

But this works anywhere:

int Temp = MyClass.MyInt;

And as another example, this would fail:

var mc = new MyClass();
mc.MyInt = 123; //this won't compile, it's not a public setter
like image 61
Nick Craver Avatar answered Jan 12 '23 02:01

Nick Craver