I am trying to understand the difference between the C# auto declaration of variables with getters & setters & the java declaration.
In java I usually do this:
private int test;
public int getTest() {
return test;
}
public void setTest(int test) {
this.test = test;
}
But in C# I tried something like this:
private int test { public get; public set};
But that did not allow access to the variable at all. So I ended up with this:
public int test { get; set; }
So this way I could access the variable test from outside of the class.
My question is, what is the difference between these two? And is the C# implementation of making the variable public a bad idea?
In C# I have declared the variable as "public". Whereas in java it is declared as "private". Does this have any impact?
Found a really good answer (in addition to those below) here