Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
1) why structer is inherting from interfaces and why not it is inherting from classes?
2) where we will use structers in real time apart from (primitive data types )?
3) what is the intention of designing structers as sealed types by default
Posted

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

However a few hints are:

1) What is the difference between as struct and a class? Can you logically derive a value type from a reference type? What would you get if you did?
2) Anywhere we need to. What is the advantage of a value type over a reference type?
3) What can you do with them if they aren't sealed?
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-Jan-13 11:41am    
1) The reasons are serious, but you did not quite explain it. 2nd sentence is the closest.
3) Anything. Inheritance between structures would be very useful. I know systems where it is allowed and good to use.
—SA
chandubbbb 29-Jan-13 0:36am    
I am a beginner ,still lerning thats why asking to know the reson behind this
1)struct is value type and class is reference type ,iknow that. Even though interface is also reference type structer is inheriting from iT
VALUES TYPES ARE DIRECTLY STORED IN MEMORY WHERE AS REFERENCE TYPES CREATE THEIR
REFERENCE VARIABLE IN STACK MEMORY AND OBJECTED IS STORED IN HEAP. REFERENCE VARIABLE POINTS TO OBJECT IN THE HEAP MEMORY AND ACCESS FROM THERE .OBVIOUSLY IT TAKES MORE TIME TO ACCES REFERENCE TYPE
2)my tutor never used structer while explaining C# STUFF.bECAUSE OF THAT ONLY I AM ASKING WHERE WE WILL USE IN REAL TIME PROJECTS
3)STRUCTER HOLDS ALL THE CLASS MEMBERS EXCEPT IT IS A VALUE TYPE THEN WHY DID THEY HAVE NOT MARKED CLASS AS SEALED AND WHY THEY HAVE MARKED STRUCTER AS SEALED TYPE
OriginalGriff 29-Jan-13 2:38am    
1) DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
2) "Even though interface is also reference type" since when?
3) "REFERENCE TYPES CREATE THEIR REFERENCE VARIABLE IN STACK MEMORY" No, not necessarily.
4) "OBVIOUSLY IT TAKES MORE TIME TO ACCES REFERENCE TYPE" Correct! Well done! That is one difference.
5) "my tutor never used structer while explaining C# STUFF" Probably, he will get to that later...
6) "STRUCTER HOLDS ALL THE CLASS MEMBERS" No - it can hold references to class members, but it can't hold the members themselves.

And you didn't think about any of my questions, did you? Go back to my first hint and think about what I asked you.

And don't shout at people you want help from - it really doesn't encourage them to be nice, at all...
chandubbbb 29-Jan-13 4:26am    
1) DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
==>Ok,I am not shouting ,By mistake I have Typed All Capital letters.Excuse me For doing such mistake
2) "Even though interface is also reference type" since when?
IN msdn only i found interface is Reference type
Reference Types (C# Reference)


Variables of reference types store references to the actual data. This section introduces the following keywords used to declare reference types:
class
interface
delegate
This section also introduces the following built-in reference types:
dynamic
object
string
6) "STRUCTER HOLDS ALL THE CLASS MEMBERS" No - it can hold references to class members, but it can't hold the members themselves.

==>I mean That structer can able to contain ALL the members like fields propeties,methods constructers in the same way as class
0) "Structers" do not exist.

1) Not a valid question. Because it's designed this way. If you are asking how to design in a different way, you should explain all of your design. But how structures would possibly inherit from classes? Classes are reference types, structures are value types.

2) Nowhere, because OS using CLR are not real time systems. :-) The question makes no sense not just because of your misuse of the term "real time", but in general.

3) Because this is designed this way. Ask the creators of .NET. I know some systems where structures can inherit. It's funny: this question was asked many times, and some members always provided "rational" explanations. They are all purely illusionary. In fact, there is no such explanation. Perhaps they just did not want to make the system more complex than it has to be. But there is nothing too difficult about inheritance between structures.

—SA
 
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