Introduction: Difference Between Class And Structure

In this post, we will learn about difference Between Class And Structure in C#.Net.

Description:

In my previous posts I have explained various topics likeĀ ASP.NET Core, C# static constructor, Nullables in C# Collections in C#SortedSet in C#.Net,Stack in C#,Queue in C#.Net,LinkedList in C#.Net. Now in this post, I will explain aboutĀ Difference Between Class And Structure with appropriate example.

Class

  1. Class is a reference type and its object is created on the heap memory.
  2. Class can inherit the another class.
  3. Class can have the all types of constructor and destructor.
  4. The member variable of class can be initialized directly.
  5. class object can not be created without using the new keyword, it means we have to use it.TestClass obj=new TestClass();

Structure

  1. Structure is a value type so its object is created on the stack memory.
  2. Structure does not support the inheritance concept.
  3. Structure can only have the parametrized constructor. it means a structure can not have the non-parametrized constructor,default constructor and destructor also.
  4. The member variable of structure can not be initialized directly.
  5. Structure object can be created without using the new keyword.(optional)TestClass obj;



Summary

I hope you got an idea about difference Between Class And Structure.
I would like to have feedback from my blog readers.
Your valuable feedback, question, or comments about this article are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website