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.