C#中的字符串和字符串数据类型是什么?

字符串代表System.String,而字符串是System.String在C#中的别名-

例如-

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

C#中的String类型允许您将任何字符串值分配给变量。字符串类型是System.String类的别名。它是从对象类型派生的。可以使用两种形式的字符串文字来分配字符串类型的值-带引号和@引号。

输出结果

String str = "Okay!";