I understand that this may be something really basic, but I'm not sure of the best practice to achieve the following.
I have the following class with a string property myString:
public class MyClass
{
public string myString
{
get {
return myString;
}
}
public void AFunction()
{
this.myString = "New Value";
}
}
I want the property myStringto do the following:
- Installed internally
- Gettable internal interface
- NOT installed outside
- The resulting look
Therefore, I want to be able to set the variable myStringinside the class and make its value read-only from outside the class.
Is there a way to achieve this without using a separate get and set function and make the property myStringprivate, for example:
public class MyClass
{
private string myString { get; set; }
public void SetString()
{
this.myString = "New Value";
}
public string GetString()
{
return this.myString;
}
}
, myString .
protected, .