I am trying to create a class that takes a value aas a parameter in its constructor. It has a private member variable that stores this value. After that, the value should not be changed.
Here is what I have, it works, but I don't think this is the best solution out there:
internal class Foo
{
private int a;
public int A
{
get
{
return this.a;
}
}
public Foo(int a)
{
this.a = a;
}
}
This way you cannot access afrom outside the class, and a-property only has a get method. However, you can still change ainside the class and use a property that returns only one variable, and nothing else looks silly.
Am I doing it right, or is there a way to improve my code / a more correct way to do this?
user2032433