C# property accessor modifiers

Description

The get and set accessors can have different access levels.

This would allow a property to have a public get and a private or protected set.

Example

In the following code example, notice that the set has a private access modifier and the get does not have any.


public string Name  
{ /*w  w  w .j a  va  2s  .c om*/
  get 
    { 
      return _name; 
    } 
  private set 
  { 
      _name = value; 
    }  
}   




















Home »
  C# Tutorial »
    Custom Types »




C# Class
C# Struct
C# Interface
C# Inheritance
C# Namespace
C# Object
C# Delegate
C# Lambda
C# Event
C# Enum
C# Attribute
C# Generics
C# Preprocessor