Articles → CSHARP → Difference Between Struct And Class In C#

Difference Between Struct And Class In C#






Difference


ClassStruct
Class supports inheritanceStruct does not support inheritance
Class is having default constructorStruct does not have default constructor.
Class is stored in heap as class is a reference typeStruct is stored in stack as struct is a value type
Garbage collector frees memory in case of class.Memory in struct is automatically reclaimed.
While passing a class as a function parameter, the reference of passing variable is copied to the function variable. So if the value of function variable is changed then the value of passing variable will also change.While passing a struct as a function parameter, the value of passing variable is copied to the function variable. So if the value of function variable is changed then the value of passing variable will not change.



Posted By  -  Karan Gupta
 
Posted On  -  Monday, February 27, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250