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

Difference Between var and dynamic in C#

 Var: Var is implicitly typed
         The type is decided at compile time
         Once assigned, the type cannot change
         strongly typed. 
         intellisese worked properly.  
         Errors are checked at compile time

Ex:
var name = "Naresh";   // Compiler treats it as string
// name = 10; ❌ Error (cannot change type)


Dynamic: dynamice is resolved ar runtime
         type checking happens at runtime, not compile time
         the type can change
         no compile time type checking
         intellisense is limited.
         errors may occur at runtime
Ex: 
dynamic value = "Naresh";
value = 10;   // ✅ Allowed

value = true; // ✅ Allowed