Saturday, May 5, 2018

C# : What is the difference between a struct and a class in C#

Answer:
Class and struct both are the user defined data type but have some major difference:

Struct
  • The struct is value type in C# and it inherits from System.Value Type.
  • Struct is usually used for smaller amounts of data.
  • Struct can’t be inherited to other type.
  • A structure can't be abstract.
  • No need to create object by new keyword.
  • Do not have permission to create any default constructor.
Class
  • The class is reference type in C# and it inherits from the System.Object Type.
  • Classes are usually used for large amounts of data.
  • Classes can be inherited to other class.
  • A class can be abstract type.
  • We can’t use an object of a class with using new keyword.
  • We can create a default constructor.

No comments:

Post a Comment