Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi folks I am new to C# world.
I am going through language specification, in which it is written as " A struct type is similar to a class type in that it represents a structure with data members and function members.
However, unlike classes, structs are value types and do not require heap allocation. Struct types do not support user-specified inheritance, and all struct types implicitly inherit from type object. ".

I have these questions:

1) Why struct doesn`t supports inheritance ?

2) Althought other value types are stored in heap, then how struct type do not require heap allocation ?

3) What is the need of struct type if we already have a class type ?


Please try to answer it as simple as possible.

Thanks in Advance.
Posted

1 solution

With all due respect this feels like a homework question.
I suggest you consult your friendly neighbourhood search engine (e.g. Google) as this has been asked a million times.

For example the following links might shine some light on your questions and for the most part were found by simply taking your question you typed there and giving it to Google (some slight syntax changes were made in some situations).

Link 1[^]
Link 2[^]
Link 3[^]

You can figure out which questions the links answer for yourself as it should be pretty obvious. If they are too complex for you, then I suggest you revisit said search engine :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900