Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Khác biệt giữa String và string trong C#

String là System.String, string là alias (bí danh) trong C# cho System.String.

Ví dụ:

string str = "Welcome!";

Không bắt buộc, nhưng thường dùng String khi làm việc với lớp (static methods).

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

Alias cho các kiểu dữ liệu khác:

Ví dụ

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