In this blog, I’m explaining the concept of properties.

Properties are special kind of class members.  Member variables or methods in a class or structures are called Fields. Properties are an extension of fields and are accessed using the same syntax. They use assessors through which the values of the private fields can be read, written or manipulated.

We use predefined set and get methods to access and modify them. Property reads and writes are translated to get and set method calls.


The get { } implementation must include a return statement. It can access any member on the class.


The set { } implementation receives the implicit argument "value." This is the value to which the property is assigned.

Properties have many uses: they can validate data before making free to  a change; they can transparently expose data on a class where that data is actually retrieved from some other source, such as a database; they can take an action when data is changed, such as raising an event, or changing the value of other fields.

Features of Properties

·     Properties can be marked as public, private, protected, internal, or protected internal. These access modifiers define how users of the class can access the property.

·   A property may be declared as a static property by using the static keyword.


There is an example student personal details.

using System;
namespace PropertiesExample
    public class Student
        public static int NumberOfStudents;
        private static int count=1;
        private string name;
        // A read-write instance property of Student class
        public string Name
            // here, get method is used to get the name
            get {
                return name;
            // here, set method is used to get the name
            set {
                name = value;
        // A read-only static property of Student class
        public static int Counter
            // here, only get count not set
            get { return count; }
        // A Constructor:
        public Student()
            // Calculate the Student's number:
            count = count + NumberOfStudents;
    class Test
        static void Main()
            Student.NumberOfStudents = 1000;    // number of student: 1000
            Student studentObj = new Student();
            studentObj.Name = "Manoj pandey";   // a new student 'manoj pandey'
System.Console.WriteLine("Student number: "+Student.Counter);   // student number is total no. of student +1
       System.Console.WriteLine("Student name: "+studentObj.Name);   // student name
       Console.ReadKey(); // hold the screen     


Student number: 1001

Student name: Manoj pandey

In this example, a new student added after number of student+1 by using get and set method.

  Modified On Sep-18-2014 01:24:24 PM

Leave Comment