我想知道它们之间的区别以及使用它们的可能方式是什么。
完全没有区别,甚至在IL级别也是一样的。在C#中,string
是指向实际的System.String
.NET类型的别名。至于可能的用途,无论何时你想在应用程序中表示一个空字符串,都可以使用它。关于string.Empty
和""
之间的区别,已经进行了很多讨论,普遍的共识是使用最适合你并使你的代码更易读的那个,这显然是主观的。
No difference, it’s just predefine text or name for compiler.
string =String (class)
int =Int32 (struct)
long= Int64 (struct)
decimal = Decimal (struct)
仅供参考: 别名-Int32和int之间有一个区别,例如:
您可以编写:
enum A : int
{
}
但你不能写成:
enum A : Int32
{
}