Instantiation
Context: Instantiation creates an object (instance) of a class using the new keyword, which allocates memory and calls the constructor.
Syntax
Section titled “Syntax”ClassName variableName = new ClassName([arguments]);Examples
Section titled “Examples”Person person1 = new Person("Alice");var person2 = new Person("Bob"); // using varPerson person3 = new() { Name = "Charlie" }; // target-typed new (C# 9+)Default Constructor
Section titled “Default Constructor”If you don’t define any constructor, the compiler provides a parameterless constructor that initializes fields to default values.
class Simple{ public int Number;}Simple obj = new Simple(); // Number = 0Object Initializers
Section titled “Object Initializers”Set public fields/properties at creation.
var car = new Car { Model = "Tesla", Year = 2025 };