在C#中,字符串/字符串的大写和小写有什么区别?
新手,C#中String/string的大小写有什么区别?
Newbie here, in C# what is the difference between the upper and lower case String/string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
字符串比字符串使用更多的像素。 因此,在黑暗的房间里,如果您的代码要使用亮暗字体阅读,它会投射更多的光。 决定使用哪个可能很棘手 - 这取决于照明像素的价格,以及您的读者是否想要投射更多或更少的光。 但 C# 为您提供了选择,这就是为什么它是全面最佳的语言。
String uses a few more pixels than string. So, in a dark room, it will cast a bit more light, if your code is going to be read with light-on-dark fonts. Deciding on which to use can be tricky - it depends on the price of lighting pixels, and whether your readership wants to cast more light or less. But c# gives you the choice, which is why it is all-around the best language.
什么都没有——两者都引用
System.String
。Nothing - both refer to
System.String
.“String”是基础 CLR 数据类型(类),而“string”是 String 的 C# 别名(关键字)。 它们是同义的。 有些人在调用 String.Format() 等静态方法时更喜欢使用 String,而不是 string.Format(),但它们是相同的。
"String" is the underlying CLR data type (class) while "string" is the C# alias (keyword) for String. They are synonomous. Some people prefer using String when calling static methods like String.Format() rather than string.Format() but they are the same.
String 是 System.String 的简短版本,System.String 是所有 .Net 语言使用的通用类型系统 (CTS) 类型。 string 是同一事物的 C# 缩写...
例如
等。
String is short version of System.String, the common type system (CTS) Type used by all .Net languages. string is the C# abbreviation for the same thing...
like
etc.
C# 中“String”类型的对象是“System.String”类型的对象,如果使用“using System”指令,编译器就会以这种方式绑定它,如下所示:
使用系统;
...
字符串 s = "嗨";
Console.WriteLine(s);
如果您要删除“using System”语句,我必须更明确地编写代码,如下所示:
System.String s = "嗨";
System.Console.WriteLine(s);
另一方面,如果您在 C# 中使用“string”类型,则可以跳过“using System”指令和命名空间前缀:
字符串 s = "嗨";
System.Console.WriteLine(s);
其有效的原因以及 C# 中的“object”、“int”等都有效的原因是因为它们是底层 .NET Framework 类型的特定于语言的别名。 大多数语言都有自己的别名,作为这些语言的现有程序员能够理解的 .NET 类型的捷径和桥梁。
An object of type "String" in C# is an object of type "System.String", and it's bound that way by the compiler if you use a "using System" directive, like so:
using System;
...
String s = "Hi";
Console.WriteLine(s);
If you were to remove the "using System" statement, I'd have to write the code more explicitly, like so:
System.String s = "Hi";
System.Console.WriteLine(s);
On the other hand, if you use the "string" type in C#, you could skip the "using System" directive and the namespace prefix:
string s = "Hi";
System.Console.WriteLine(s);
The reason that this works and the reason that "object", "int", etc in C# all work is because they're language-specific aliases to underlying .NET Framework types. Most languages have their own aliases that serve as a short-cut and a bridge to the .NET types that existing programmers in those languages understand.
没有不同。
字符串只是字符串的同义词。
no difference.
string is just synonym of String.
string 是 .NET Framework 中 String 的别名。
string is an alias for String in the .NET Framework.
String 是来自 .NET core (CLR) 的类型。
string 是 C# 类型,在编译的 IL 中被转换为 String。
语言类型被转换为 CLR 类型。
String is type coming from .NET core (CLR).
string is C# type, that is translated to String in compiled IL.
Language types are translated to CLR types.