Wednesday, February 11, 2026

What is a Class Member in C#

  class members are the variable and functions that are defined inside a class.

  anything written inside a class is called a class members

  types of class members

  Fields
  propertied
  methods
  constructors
  events
  indexers
  and  Nested class

  Ex : public class Employee
  {
  // Field
  private string name;

  // Property
  public string Name { get; set; }

  // Method
  public void Display()
  {
  Console.WriteLine("Employee Name");
  }

  // Constructor
  public Employee()
  {
  Console.WriteLine("Constructor Called");
  }
  }

  "Class members are the variables, properties, methods, and constructors defined inside a class. They represent the data and behavior of the class." 
  

 Fields  - Store data
 Properties - Control data access
 Methods - perform actions

 Constructor  - initialize object