Home > DeveloperSection > Interviews > c# - Difference between class and structure.

Posted on    May-05-2016 5:46 AM

 C# C#  OOPS 
 1 Answer(s)
  343  View(s)
Rate this:

Chris S
Chris S

Total Post:23

Posted on    May-05-2016 5:46 AM

1. Classes are usually used for large amounts of data, whereas structs are usually used for smaller amounts of data.

2. Classes can be inherited whereas structures not.

3. A structure couldn't have a destructor such as a class.

4. A structure can't be abstract, a class can.

5. A structure must always have the default parameter less constructor defined as public but a class might have one, so you can't define a private parameter-less constructor as in the following:

6. Class is a reference type and its object is created on the heap memory, whereas structure is a value type that is why its object is created on the stack memory.

7. Class can inherit another class, whereas structure does not support the inheritance.

8. Class object cannot be created without using the new keyword; it means we have to use it.             Demo obj=new Demo();

    whereas structure object can be created without using the new keyword.(optional) Demo obj;

Modified On May-05-2016 05:51:06 AM

Don't want to miss updates? Please click the below button!

Follow MindStick