What are the differences between the class and structure?

What are the differences between the class and structure?

Last updated:8/23/2021 7:05:41 AM

1 Answers

Ashutosh Kumar Verma
Ashutosh Kumar Verma

Different between class and interface-

                                                                 Class                                                                     Structure
1- Class is reference type. Structure is value types.
2- Instance is not created without 'new' keyword of class Objects are created with and without 'new' keyword of structure.
3- A class is declared by using 'class' keyword A structure is created by using 'struct' keyword 
4- Values can assign of all types variables in a class. In structure value are not assigned to the variables instead of 'const' and 'static' variable.
5- Class access the reference of variables value. It does not store the value directly in memory It directly access the value from variables and also store direct value of variables in memory. 
6- It is slower than structure. It is faster than a class.
ex-  class Demo
{
private int a=10; 
public string name='Ashu';
int age;
}
ex- struct Demo
{
private const string name='Ashu';
public string location;
}


Answer