Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Struct & Class both are the user defined data type but have some major differences:

# Struct Class
1. Structure are value type in C# & it inherits from System.ValueType. Classes are reference type & it inherits from the System.Object Type.
2. Structure use stack to store value. classes use heap to store value.
3. Structure can not be declared as protected . Classes can not declare as protected.
4. We can not be able to use inheritance in Structure. We can use inheritance in classes.
5. The struct can have the only constructor. The class can have the constructor and destructor.
6. Structure objects can not destroy using GC. Objects created from classes are terminated using GC.
7. The struct can instantiate without using the new keyword.. The new keyword should be used to create the object for the class.
8. The struct can only inherit the interfaces. The class can inherit the interfaces, abstract classes.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Top 100 C# interview questions and answers 2022

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What are the similarities between a struct and a c... >>
<< What are IDE’s provided by Microsoft for C# deve...