---
title: "Properties"  
description: "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 stru"  
author: "Anchal Kesharwani"  
published: 2014-08-12  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/673/properties  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# Properties

In this blog, I’m explaining the concept of [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties).\

Properties are special kind of class members. Member [variables](https://www.mindstick.com/articles/715/php-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.

##### Get

The get { } [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) must include a [return statement](https://answers.mindstick.com/qa/82430/why-do-we-use-return-statement-in-c-sharp). It can access any member on the class.

##### Set

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](https://www.mindstick.com/forum/2066/validate-data-when-textbox-loses-focus) 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](https://www.mindstick.com/articles/338838/explain-access-modifiers-in-java) define how users of the class can access the property.

· A property may be [declared as](https://www.mindstick.com/interview/2711/what-if-the-main-method-is-declared-as-private) a static property by using the [static keyword](https://www.mindstick.com/forum/105398/what-is-the-static-keyword).

##### Example

There is an example student [personal details](https://answers.mindstick.com/qa/93397/are-my-personal-details-at-mindstick-profile-safe-and-secure).

```
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       }    }}
```

##### Output:

Student number: 1001

[Student name](https://www.mindstick.com/forum/157178/how-to-filter-1000-of-student-name-in-php-in-ascending-order): Manoj pandey

In this example, a new student added after number of student+1 by using get and set method.

---

Original Source: https://www.mindstick.com/blog/673/properties

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
