C# 中的 String 和 string 有什麼區別?


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

更新於:2020 年 6 月 21 日

456 次瀏覽

開啟您的 職業

完成學習並獲得認證

開始學習
廣告
© . All rights reserved.