Code Structure Overview

This program demonstrates the evolution of property implementation in C#, from traditional getter/setter methods to modern .NET properties.

Main Method Analysis

static void Main(string[] args)
{
    Person person = new Person();
    person.Name = "abc";        // Calls the Name property's SET accessor
    person.Address = "Kolkata"; // Calls the Address property's SET accessor
    string details = person.GetDetails();
    Console.WriteLine(details);
    Console.ReadLine();
}

What happens:

  1. Creates a new Person object
  2. Sets the Name property to "abc" (internally calls the setter)
  3. Sets the Address property to "Kolkata"
  4. Calls GetDetails() method to get formatted output
  5. Displays the result and waits for user input

Person Class Breakdown

1. Private Fields (Encapsulation)

#region Private Members
private int _No;
private string _Name;
private string _Address;
#endregion

These are backing fields - private variables that store the actual data. The underscore prefix (_) is a common naming convention for private fields.

2. Properties (Modern .NET Approach)

public string Name
{
    get { return "Mr / Mrs  " + _Name; }  // Getter: formats the name
    set { _Name = value; }                // Setter: stores the value
}

public string Address
{
    get { return _Address; }              // Simple getter
    set { _Address = value; }             // Simple setter
}

Key Points: