This means that you cannot set this property from an instance of the class. Only a member of the same class can set it. Therefore, for outsiders, this property becomes the read-only
property.
class Foo { public string Name1 { get; set; } public string Name2 { get; private set; } public string Name3 { get { return Name2; } set { Name2 = value; } }
Then
Foo f = new Foo(); f.Name1 = ""; // No Error f.Name2 = ""; // Error. f.Name3 = ""; // No Error
Name3
set the value to Name2
, but the setting value in Name2
is not directly possible.
and how much do they have?
Since the properties Name1
and Name3
are publicly available, therefore they and their get and set methods are available everywhere.
Name3
also publicly available, but its set is private, so the property and get method will be available everywhere. The method range is limited only by the class (the private
access modifier has a scope within the object where it is defined).
source share