C#无效类型 - 安全 [英] C# void type- safety

查看:158
本文介绍了C#无效类型 - 安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是新的C#编程(从C ++来)

I am just new for C# programming (coming from C++)

我的问题是:
在C#中每一个类型的对象
为什么要继承无效不`吨?它可能会导致一些RT /类型安全问题,或者它只是语义/语法?

My question is: In C# every type inherits from Object Why 'void' doesn`t?Can it cause some RT/type safety problems or it is just semantics/syntax?

(我知道,INT /炭等一个'基地类型'和拳击/拆箱使用 - 我的问题是具体的无效)

(I know that int/char etc a 'base type' and boxing/unboxing is used - my question is specific for void)

感谢您

推荐答案

在C#中, 无效 是用于两种上下文中的关键词:

In C#, void is a keyword that is used in two contexts:


  • 在方法的上下文签名,无效表示没有返回类型;它不是指一种空白,这可能从对象继承。

  • In the context of method signatures, void indicates the absence of a return type; it doesn't refer to a type "void" which could inherit from object.

(反射,一返回类型一直被指定。出于这个原因,有一个 System.Void 键入框架,但无效 System.Void 不能互换使用。)

(In reflection, a return type has always to be specified. For this reason, there is a System.Void type in the framework, but void and System.Void cannot be used interchangeably.)

在不安全的情况下,无效* 是一个指针类型一个未知的类型。正如博客文章通过链接的 @Colin麦凯的,指针类型不从对象,虽然他们可以被转化为一个。

In unsafe context, void* is a pointer type to an unknown type. As mentioned in the blog post linked by @Colin Mackay, pointer types do not inherit from object, although they can be converted to one.

这篇关于C#无效类型 - 安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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