C#中:&QUOT之差; System.Object的"和"对象"

编程入门 行业动态 更新时间:2024-10-23 21:24:18
本文介绍了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的"和"对象"

本文发布于:2023-05-25 10:55:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:之差   对象   QUOT   Object   System

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!