+ 2

Struct vs Class in C#

This is not a question, it is just to clarify the difference between struct and class

6th Nov 2016, 11:40 PM
Maduekwe Ebuka Collins
Maduekwe Ebuka Collins - avatar
1 Odpowiedź
+ 9
the basic difference is in the instantiation..a struct by default is not initialized using the new keyword bt a class is. this means that struct doesn't have a default constructor just like classes (unless otherwise created). Also struct is a value type while class is a reference type. This means that struct variables directly hold the values themself but class variables are more like reference to the value, they hold they address to the value. value type variables are stored on the stack memory where they directly hold the values while reference type variables store the values on the heap memory and then the reference to this value is then stored on the stack memory.
6th Nov 2016, 11:43 PM
Maduekwe Ebuka Collins
Maduekwe Ebuka Collins - avatar