Variables vs Properties
int age; // Variable declaration
age = 25; // Variable assignment
Console.WriteLine(age); // Accessing variable to read its value
age = 30; // Modifying the variable
Console.WriteLine(age); // Accessing modified valuepublic class Person
{
private string name; // Private field
public string Name // Property
{
get { return name; } // Getter method
set { name = value; } // Setter method
}
}
Person person = new Person();
person.Name = "John"; // Setting the property value
Console.WriteLine(person.Name); // Accessing the property valueLast updated