Home  • Courses • Software Engineering

Field and Properties (C#)

Lecture: - declare fields/variables as private - provide public get and set methods, through properties, to access and update the value of a private field
class Person{
  private string name; // field
  public string Name{ get; set; } // property
}

class Program
{
  static void Main(string[] args)
  {
    Person person= new Person();
    person.Name = "Zahid";
    Console.WriteLine(person.Name);
  }
}

Comments 1


odd namber "Bejor namber" and Even namber"Jor namber"
Copyright © 2024. Powered by Intellect Software Ltd