c#中有任何派生数据类型吗?它们是什么? [英] Are there any derived data types in c#.what r they?
本文介绍了c#中有任何派生数据类型吗?它们是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
c#中是否有任何派生数据类型?
解决方案
C#中的所有数据类型都是派生的,但除外object
,这是从中派生所有其他类的根类。
来自对象
您将获得引用类型,例如string
,以及所有类
类型,以及ValueType
,所有struct
和basic数据类型,例如int
,float
,double
,char
等等已经诞生。
这就是为什么你可以将任何类型的数据分配给对象
变量:
< pre lang =c#> string s = 你好有编码器!;
string [] words = s.Split(' ');
int val = 42 ;
object o = s;
o =字;
o = val;
o = true ;
请看这里:
http://stackoverflow.com/questions/4729094/value-types-inherit-from-system-object-why [<一个href =http://stackoverflow.com/questions/4729094/value-types-inherit-from-system-object-whytarget =_ blanktitle =New Window> ^ ]
在实际的基础上,你可能表现得好像 .NET中的所有东西都是一个对象;然而,从技术上讲,这并不完全正确,正如Eric Lippert在并非一切都来自于对象:中所指出的那样:[ ^ ]。
接口派生来自Interface,而不是Object,但正如Eric指出的那样,它们可以转换为Object。
Are there any derived data types in c#.what r they?
解决方案
All datatypes in C# are derived, with the exception ofobject
, which is the root class from which all others are derived.
Fromobject
you get reference types such asstring
, and allclass
types, and theValueType
, from which allstruct
and "basic" datatypes such asint
,float
,double
,char
, etc. are born.
Which is why you can assign any type of data to anobject
variable:
string s = "hello there coder!"; string[] words = s.Split(' '); int val = 42; object o = s; o = words; o = val; o = true;
Please have a look here:
http://stackoverflow.com/questions/4729094/value-types-inherit-from-system-object-why[^]
On a practical basis, you might as well act as if everything in .NET "is" an Object; however, technically, that's not quite true, as Eric Lippert points out in "Not everything derives from object:" [^].
Interfaces derive from Interface, not Object, but, as Eric points out, they can be converted into an Object.
这篇关于c#中有任何派生数据类型吗?它们是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文