String 和 C# 中的 string 有什么区别?

csharpprogrammingserver side programming更新于 2025/10/13 10:37:17

String 代表 System.String,而 string 在 C# 中是 System.String 的别名。

例如

string str = "Welcome!";

这并非必需,但在使用类时通常使用 String。

string str = String.Format("Welcome! {0}!", user);

由于 string 是 System.String 的别名,因此其他数据类型的别名如下:−

示例

object: System.Object
string: System.String
bool: System.Boolean
float: System.Single
double: System.Double
decimal: System.Decimal
byte: System.Byte
sbyte: System.SByte
short: System.Int16
ushort: System.UInt16
int: System.Int32
uint: System.UInt32
long: System.Int64
ulong: System.UInt64
char: System.Char

相关文章