C# - DIFFERENCE BETWEEN CLASS AND STRUCTURE.

Chris S

Total Post:23

Points:115
Posted by  Chris S
C#  OOPS 
C#
 619  View(s)
Ratings:
Rate this:
  1. Chris S

    Post:23

    Points:115
    c# - Difference between class and structure.

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!