Newbie here, in C# what is the difference between the upper and lower case String/string?
这里的新手,在C#中大小写字符串/字符串有什么区别?
9 个解决方案
#1
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.
String使用比字符串多几个像素。因此,如果您的代码将使用浅色字体读取,那么在黑暗的房间中,它会投射更多光线。决定使用哪个可能很棘手 - 这取决于照明像素的价格,以及您的读者是否想要投射更多光线或更少。但是c#为您提供了选择,这就是为什么它是全方位的最佳语言。
#2
Nothing - both refer to System.String
.
什么都没有 - 都引用System.String。
#3
"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”是底层CLR数据类型(类),而“string”是String的C#别名(关键字)。他们是同义词。有些人喜欢在调用String.Format()等静态方法而不是string.Format()时使用String,但它们是相同的。
#4
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...
String是System.String的简短版本,是所有.Net语言使用的通用类型系统(CTS)类型。 string是同一件事的C#缩写......
like
- System.Int32 and int
- System.Int16 and short,
System.Int32和int
System.Int16和简称,
etc.
#5
This is explained in great detail on MSDN. I'd suggest going to the source. :)
这在MSDN上有详细解释。我建议去消息来源。 :)
#6
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.
C#中“String”类型的对象是“System.String”类型的对象,如果使用“using System”指令,它就会被编译器绑定,如下所示:using System; ... String s =“嗨”; Console.WriteLine(一个或多个);如果要删除“using System”语句,我必须更明确地编写代码,如下所示:System.String s =“Hi”;的System.Console.WriteLine(一个或多个);另一方面,如果在C#中使用“string”类型,则可以跳过“using System”指令和名称空间前缀:string s =“Hi”;的System.Console.WriteLine(一个或多个);这有效的原因以及C#中“object”,“int”等所有工作的原因是因为它们是底层.NET Framework类型的特定于语言的别名。大多数语言都有自己的别名,可以作为这些语言中现有程序员理解的.NET类型的捷径和桥梁。
#7
no difference. string is just synonym of String.
没有不同。 string只是String的同义词。
#8
string is an alias for String in the .NET Framework.
string是.NET Framework中String的别名。
#9
String is type coming from .NET core (CLR).
字符串是来自.NET核心(CLR)的类型。
string is C# type, that is translated to String in compiled IL.
string是C#类型,在编译的IL中转换为String。
Language types are translated to CLR types.
语言类型转换为CLR类型。
#1
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.
String使用比字符串多几个像素。因此,如果您的代码将使用浅色字体读取,那么在黑暗的房间中,它会投射更多光线。决定使用哪个可能很棘手 - 这取决于照明像素的价格,以及您的读者是否想要投射更多光线或更少。但是c#为您提供了选择,这就是为什么它是全方位的最佳语言。
#2
Nothing - both refer to System.String
.
什么都没有 - 都引用System.String。
#3
"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”是底层CLR数据类型(类),而“string”是String的C#别名(关键字)。他们是同义词。有些人喜欢在调用String.Format()等静态方法而不是string.Format()时使用String,但它们是相同的。
#4
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...
String是System.String的简短版本,是所有.Net语言使用的通用类型系统(CTS)类型。 string是同一件事的C#缩写......
like
- System.Int32 and int
- System.Int16 and short,
System.Int32和int
System.Int16和简称,
etc.
#5
This is explained in great detail on MSDN. I'd suggest going to the source. :)
这在MSDN上有详细解释。我建议去消息来源。 :)
#6
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.
C#中“String”类型的对象是“System.String”类型的对象,如果使用“using System”指令,它就会被编译器绑定,如下所示:using System; ... String s =“嗨”; Console.WriteLine(一个或多个);如果要删除“using System”语句,我必须更明确地编写代码,如下所示:System.String s =“Hi”;的System.Console.WriteLine(一个或多个);另一方面,如果在C#中使用“string”类型,则可以跳过“using System”指令和名称空间前缀:string s =“Hi”;的System.Console.WriteLine(一个或多个);这有效的原因以及C#中“object”,“int”等所有工作的原因是因为它们是底层.NET Framework类型的特定于语言的别名。大多数语言都有自己的别名,可以作为这些语言中现有程序员理解的.NET类型的捷径和桥梁。
#7
no difference. string is just synonym of String.
没有不同。 string只是String的同义词。
#8
string is an alias for String in the .NET Framework.
string是.NET Framework中String的别名。
#9
String is type coming from .NET core (CLR).
字符串是来自.NET核心(CLR)的类型。
string is C# type, that is translated to String in compiled IL.
string是C#类型,在编译的IL中转换为String。
Language types are translated to CLR types.
语言类型转换为CLR类型。