A constructor in C# is a special method inside a
class that runs automatically when you create an object with new.
This page covers Constructor in C#. For a language-agnostic introduction, see Constructor.
Defining a Constructor#
A constructor has the same name as the class and no return type — not even void.
public class Player
{
public string Name;
public Player(string name)
{
Name = name;
}
}Name = name stores the argument on the object so it’s available later.