Difference between a struct and a class in C#
In this post,we will learn about Difference between a struct and a class in C#.
In my previous posts I have explained various topics like Boxing & Unboxing in C# ,Dynamic Type In C#, Named Arguments In C#, Basics Of Pointers In C#, Get site visitor count in asp.net, Convert generic list to datatable in Asp.Net C#.Net, Abstract Class in C# with Example.
Now in this post, I will explain about Difference between a struct and a class in C#. Class and struct both are the user defined data type but have several major difference in them.
- The struct is value type in C# and it inherits from System.Value namespace.
- It is mostly used for smaller amounts of data.
- Struct can not be inherited to other type.
- A structure can not be abstract.
- No need to create object by new keyword.
- Struct do not have permission to create any default constructor for its type.
- The class is reference type in C# and it inherits from the System.Object namespace.
- These are usually used for large amounts of data.
- It can be inherited to other class.
- A class can be abstract type.
- We can not use an object of a class with using new keyword.
- We can create a default constructor for class.
I hope you got an idea about Difference between a struct and a class in C#.
I would like to have feedback from blog my readers.
Your valuable feedback, question, or comments about this article are always welc