字符串与字符串! [英] string versus String !
本文介绍了字符串与字符串!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
字符串与字符串!
我有一个问题(有点尴尬,因为我这么晚才看到). String和string有什么区别?不能以String为类,而string为引用类型的方式.而是如何在使用方面考虑它们.
string versus String!
I have a question (a little embarrassing because I see it so late). What is the difference between String and string? Not in the way that String is a Class and string is a reference type. But rather how to think about them in the term of uses.
我搜索并找到了这块黄金,但是我不知道如何很好地使用它:
I searched and find this piece of gold, but I don''t know how to use it very well:
- 使用字符串"来专门指代String类.
- 在引用String类的对象时,请使用字符串".
如何相应地使用它们?
How to use them, accordingly?
再次感谢.
推荐答案
字符串==字符串.它们是同一类的别名,就像ulong是UInt64的别名
String == string. They''re aliases of the same class, just like ulong is an alias of UInt64
一样.string
是String
的C#别名(实际上是System.String
).当代码编译时,所有string
类型都将在IL中转换为System.String
.个人而言,我更喜欢在键入变量时使用string
,在访问变量时使用String
类的静态成员.这只是个人喜好,因为我认为这使代码更易于遵循.像这样的代码没有什么问题:
There is no difference.string
is the C# alias toString
(which is reallySystem.String
). When the code compiles, all of yourstring
types are converted toSystem.String
in the IL.
Personally, I prefer usingstring
when I am typing a variable andString
when I am acessing static members of the class. This is only personal preference as I think it makes the code easier to follow. There is nothing wrong with code like:
bool empty = string.IsNullOrEmpty("");
而不是
bool empty = String.IsNullOrEmpty("");
这篇关于字符串与字符串!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文