The following are the differences between a class and a structure in C# language:


Class Structure
In C# language, a class is defined by using the class keyword. For example, public class StudentReport{….} In C# language, a structure is defined by using the struct keyword. For example, public struct StudentReport{….}
A class is a reference type and its object is created on the heap. A structure is a value type and its object is created on the stack.
A class can be inherited from a class or struct. A structure does not support inheritance and cannot be inherited from any class or struct.
A class is more efficient when used in collections. A structure is more efficient when used in arrays.
A class can have a default constructor without any parameter, which is provided by the common language runtime (or CLR). It also supports destructors. A structure cannot have any parameterless constructor or the default constructor that is provided by the CLR. It also cannot have destructors.
An instance field or a member variable can be initialized in a class. An instance field or a member variable cannot be initialized in a struct.
A class cannot be created without using the new keyword. For example, StudentReport StudRepo = new StudentReport(stud_enroll, stud_name, stud_report); A struct can be created without using the new keyword. For example, StudentReport StudRepo;

0 comments: