字符串和字符串之间的区别? [英] The difference between String and string?

查看:137
本文介绍了字符串和字符串之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,有Stringstring.
它们之间有什么区别?
互联网上的大多数人说,他们几乎是相同的.但是在我的程序中,使用string是错误的,而使用String是正确的.我只定义一个常量字符串.

In C#,there are String and string.
What''s the difference between them?
A majority of people on the interenet say that they are nearly the same. But in my program, using string is wrong, and using String is right. I just define a constant string.

推荐答案

无.没有区别. 字符串(C#参考) [字符串 [
None. There is no difference. string (C# Reference)[^]. The string type represents a sequence of zero or more Unicode characters. string is an alias for String[^] in the .NET Framework.


应该没有区别.请向我们显示相关代码以获得更好的帮助.
:-)
There should be NO difference. Please show us the relevant code for better help.
:-)


这里的一些答案是正确的,有些不是.
正确答案是说没有区别的答案.您可以在任何可以使用string的地方使用System.String,反之亦然.

更确切地说,"string"是由System.String(别名)支持的关键字.

现在,我可以给您一个为什么您可能会在String上使用prefer字符串的原因:代码"System.String"更长,但是"String"可能无法编译,因为您可以选择不添加"using System"(我经常避免使用它),但是"string"将始终有效.关于"System.Object"与"object"相同的内容,以后者为佳.

—SA
Some answers here are correct, some are not.
Right answers are the ones which say there is no difference. You can use System.String anywhere you can use string and visa versa.

More exactly, "string" is a keyword backed by System.String (alias).

Now, I can give you one reason why you may prefer string over String: The code "System.String" is longer, but just "String" may not compile, because you may choose not to add "using System" (I often avoid some using it), but "string" will always work. Same things about "System.Object" vs "object", the later is better.

—SA


这篇关于字符串和字符串之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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