Thursday, May 30, 2013

Write only Properties

As the name suggests write-only properties are those which can be assigned from external classes but the value cannot be read from any external class.

In general a property has get {} and set {} accessors, to create a write-only property we just need to define the set {} accessor for the property without the get {} accessor.

The following example defines a write-only property for the private variable strName
     class Employee
        private string strName;
        public string Name
                strName = value;

If we try to get the value from a write-only property then the compiler will throw the error.

The property or indexer 'XXXX' cannot be used in this context because it lacks the get accessor.

Search Flipkart Products:

No comments: