If you want the value not to be affected after initialization, you can use the keyword readonly:
public class Class2
{
public readonly string MyProperty;
public Class2()
{
MyProperty = "value";
}
}
readonly (C # link):
:
- .
- , , , , . , readonly out ref.
, , :
public class Class1
{
public string MyProperty { get; private set; }
public Class1()
{
MyProperty = "value";
}
}