
How do you introduce a ReadOnly property in C# (C Sharp)?If you want
to define a property whose value can only be read but not set, then you
can do it using ReadOnly property in C#. ReadOnly is achieved by defining
only the get accessor method for the property. The property will not have
a set accessor method. Output of
this code will be: Obj.Member1
= sample message In this example,
the property Member1 is readonly since it has only the get accessor method.
If the Main method includes the following line of code: obj.Member1
= test message; Then you
will get the following error since the property Member1 is readonly: Property
or indexer sampleClass.Member1' cannot be assigned to -- it is read
only
_______________________________________________________________________
FREE
Subscription
Subscribe
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________ |