C#中:&QUOT之差; System.Object的"和"对象" [英] c#: difference between "System.Object" and "object"

查看:123
本文介绍了C#中:&QUOT之差; System.Object的"和"对象"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,有没有使用 System.Object的在code,而不是任何区别只是对象 System.String ,而不是字符串等等?或者是它只是一个风格问题?

In C#, is there any difference between using System.Object in code rather than just object, or System.String rather than string and so on? Or is it just a matter of style?

是否有一个原因,一种形式是preferrable其他?

Is there a reason why one form is preferrable to the other?

推荐答案

字符串全球:: System.String的别名。它只是语法糖。两者的究竟的互换,而且会在编译code没有区别。

string is an alias for global::System.String. It's simply syntactic sugar. The two are exactly interchangable, and there'll be no difference in the compiled code.

我个人使用的变量名等别名,但我用的CLR类型名称在API的名称,例如:

Personally I use the aliases for variable names etc, but I use the CLR type names for names in APIs, for example:

public int ReadInt32() // Good, language-neutral

public int ReadInt() // Bad, assumes C# meaning of "int"

(请注意,返回类型是不是一个真正的名字 - 这是连接codeD作为元数据的类型,所以有没有出现混乱)

(Note that the return type isn't really a name - it's encoded as a type in the metadata, so there's no confusion there.)

这篇关于C#中:&QUOT之差; System.Object的"和"对象"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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