C# property accessor modifiers

In this chapter you will learn:

  1. What are C# property accessor modifiers
  2. Example for 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  
{ //from   w ww. ja va2  s .co  m
  get 
    { 
      return _name; 
    } 
  private set 
  { 
      _name = value; 
    }  
}   

Next chapter...

What you will learn in the next chapter:

  1. What is C# read only property
  2. How to create read only property
  3. Read-only calculated properties
Home »
  C# Tutorial »
    C# Types »
      C# Properties
C# Properties
C# property accessor modifiers
C# read or write only property
C# Automatic properties
C# Static Properties
C# Abstract Properties