Class Vs Struct in C#.NET

Hi guys ,

This article describe the difference between a class and struct data type in C#.NET

Class:
    A class is a reference type.
    A class is a user defined data type that behaves like built in data type.
    While instantiating a class, .NET runtime engine allocates memory for its instance in heap.
    Classes support inheritance.
    Variables of a class can be assigned as null.
    Class can contain constructor/destructor.

Structure:
    A structure is a value type.
    A structure is a user defined data type that behaves like built in data type.
    In structure, memory is allocated on stack.
    Structures do not support inheritance.
    Structure members cannot have null values.
    Structure does not require constructor/destructor and members can be initialized automatically.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s