Professional Documents
Culture Documents
Introduction To Constructors, Partial Classes, and Static Classes
Introduction To Constructors, Partial Classes, and Static Classes
Constructors, Partial
Classes, and Static Classes
Constructors
Constructors are special methods in a class that are used to initialize the object. They have the same name as
the class and do not have a return type. Constructors are automatically called when an object is created.
They can be used to set initial values for the object's properties or perform any necessary setup tasks.
using System;
public class Wine
{
public decimal Price;
public int Year;
public Wine (decimal price) { Price = price; }
public Wine (decimal price, int year) : this (price)
{
Year = year;
}
}