Classes vs Structures in C#

CsharpProgrammingServer Side Programming

In C#, a structure is a value type data type. It helps you to make a single variable hold related data of various data types. The struct keyword is used for creating a structure.

When you define a class, you define a blueprint for a data type.

The following are the differences between classes and structures in C# −

  • Classes are reference types and structs are value types

  • Unlike classes, structures cannot inherit other structures or classes.

  • Structures cannot be used as a base for other structures or classes.

  • When you create a struct object using the New operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the New operator.

  • Structures do not support inheritance

  • Structures cannot have a default constructor

raja
Published on 03-Aug-2018 12:11:46
Advertisements