Class


Class is a reference type with data and related functionalities encapsulated as a single unit. It serves as a blueprint for objects.

  • It is declared using the class keyword.
  • It contains data members like fields, properties, methods, and events.
  • It can be declared either public or internal (internal is the default access modifier).
  • Its members can be publicprivate or internal (members are private by default).
  • Instance of a class or an object can be created using the new keyword.
  • It can directly inherit only one base class.
  • It can implement multiple interfaces.
  • It has a base type of System.Object.
Example
namespace MyConsoleApp
{
    class Language
    {
        public string lang = "EN"; //Field
        public string Country { get; set; } //Property
        public virtual void Greeting() //Method
        {
            Console.WriteLine("Hello!");
        }
    }
}

Back to Notes