C 中string和String的區別

2022-02-05 04:17:39 字數 1210 閱讀 3622

首先運用msdn官網的解釋:thestringtype represents a string of unicode characters.stringis an alias for system.string in the .net framework.

說的是string型別其實代表了一種統一編碼的特性,在.net framwork  中"string"是system.string的乙個別名而已。

再引用乙個部落格的理解: :

c# defines a number of aliases for clr types. they may be used interchangably, and even mixed together, e.g.

string x = new system.string(' ', 5);.

these are the aliases defined:

alias

clr type

string

system.string

sbyte

system.sbyte

byte

system.byte

short

system.int16

ushort

system.uint16

intsystem.int32

uint

system.uint32

long

system.int64

ulong

system.uint64

char

system.char

float

system.single

double

system.double

bool

system.boolean

decimal

system.decimal

說在c#中為clr型別定義了很多的別名,說明string其實和string的用法一樣,只不過是不同程式設計師的使用習慣罷了。我也看了一些別人的理解,string其實在c#語言中是一種標記,也就是string是c#中的關鍵字他代表了framwork中的string型別,所以毫無疑問既然是關鍵字string就不能作為其他任何型別變數的名字了。編譯器在解釋的時候吧string編譯為string型別,由此可見如果用string就能減少編譯器的一些負擔,提高執行效率。

C 中string和String的區別

string是string的別名。string是c 中的類,string是.net framework的類 在c ide中不會顯示藍色 c string對映為.net framework的string 如果用string,編譯器會把它編譯成string,所以如果直接用string就可以讓編譯器少做一...

C 中String和string的區別

在c 程式設計時,有時碰到string,有時碰到string,可是感覺二者都可以,所以決定總結下二者的區別。msdn microsoft developers network 中對string的說明 stringis analiasforstringin the net framework。即str...

C 中,String和string的區別

c 中,字串的宣告,你使用string還是string?string?string?只有乙個大小寫的問題,你習慣用哪個?知道具體的區別嗎?我是習慣了用string,區別也是最近才找到了權威的根據,clr via c 其實,string是clr的型別名稱 也算是keyword 而string是c 中的...