This documentation is archived and is not being maintained.

Objects, Classes and Structs (C# Programming Guide)

C# is an object-oriented programming language, and uses classes and structs to implement types such as Windows Forms, user interface controls, and data structures. A typical C# application consists of classes defined by the programmer, combined with classes from the .NET Framework.

C# provides many powerful ways of defining classes, such as providing different access levels, inheriting features from other classes, and allowing the programmer to specify what happens when types are instantiated or destroyed.

Classes can also be defined as generic through the use of type parameters that enable client code to customize the class in a type-safe and efficient manner. A single generic class, for example System.Collections.Generic.List in the .NET Framework Class Library, can be used by client code to store integers, strings, or any other type of object.

Objects, classes and structs have the following properties:

  • Objects are instances of a given data type. The data type provides a blueprint for the object that is created — or instantiated — when the application is executed.

  • New data types are defined using classes and structs.

  • Classes and structs form the building blocks of C# applications, containing code and data. A C# application will always contain of at least one class.

  • A struct can be considered a lightweight class, ideal for creating data types that store small amounts of data, and does not represent a type that might later be extended via inheritance.

  • C# classes support inheritance, meaning they can derive from a previously defined class.

For more information, see the following sections in the C# Language Specification:

  • 1.6 Classes and Objects

  • 1.7 Structs

  • 3.4.4 Class Members

  • 4.2.1 Class Types

  • 10 Classes

  • 11 Structs