为什么struct不支持用户定义的继承。 [英] Why struct doesn`t supports user defined inheritance.

查看:119
本文介绍了为什么struct不支持用户定义的继承。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好我是C#世界的新手。

我正在通过语言规范,其中它被写成结构类型类似于类类型,因为它代表了一个结构数据成员和函数成员。

但是,与类不同,结构是值类型,不需要堆分配结构类型不支持用户指定的继承,并且所有结构类型都隐式地从类型对象继承。。



我有这些问题:



1)为什么struct不支持继承?



2) Althought其他值类型是存储在堆中,那么struct类型如何不需要堆分配?



3)如果我们已经有了struct类型的需要是什么班级类型?





请尽量回答它。



先谢谢。

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.

推荐答案

所有du尊重这就像是一个家庭作业问题。

我建议你咨询友好的社区搜索引擎(例如 Google )已被问过一百万次。



例如以下链接可能会闪耀您可以通过简单地将问题输入Google并将其提交给Google(在某些情况下进行了一些轻微的语法更改)来找到您的问题并且大部分内容。



链接1 [ ^ ]

Link 2 [ ^ ]

Link 3 [ ^ ]



您可以找出链接为自己回答的问题,因为它应该非常明显。如果它们对你来说过于复杂,那么我建议你重新访问所说的搜索引擎: - )
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 :-)


这篇关于为什么struct不支持用户定义的继承。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆