Auto Implemented Properties in c#


The properties with no implementation inside Get or Set are called as Auto Implemented properties.


  //Syntax for Auto implemented property

        public int StudentId

        {

            get;

            set;

        }



When you use Auto implemented properties , compiler creates the private fields in the background.


Example for Auto Implemented Properties in C#



using System;

 

namespace ProgramCall

{

    class Student

    {

        // Auto implemented properties

        public int StudentId

        {

            get;

            set;

        }

 

        public string StudentName { get; set; }

 

    }

 

 

    class MainClass

    {

        static void Main(string[] args)

        {

            Student myStudent = new Student { StudentId = 1000, StudentName = "Niranjan" };

 

            Console.WriteLine(myStudent.StudentName);

            Console.Read();

        }

    }

}



Reference MSDN



Auto Implemented Properties .net, only get set c#.net,