C#中,String和string的區別

來源:互聯網
上載者:User

C#中,字串的聲明,你使用String還是string?
String? string? 只有一個大小寫問題,你習慣用哪個?知道具體的區別嗎?
我是習慣了用string,區別也是最近才找到了權威的根據,'CLR via C#'。
其實,String是CLR的類型名稱(也算是keyword),而string是C#中的keyword。在C#的編譯時間,預設會增加幾行代碼,看了你就會明白string和String的區別了!
using string = System.String; using sbyte = System.SByte; using byte = System.Byte; using short = System.Int16; using ushort = System.UInt16; using int = System.Int32; using uint = System.UInt32; ... ...
對了! using string = System.String; C#編譯器,會自動的把string轉化為Sysem.string!
在CLR via C#中,Jeffrey Richter建議coding時,使用CLR預設的類型,也就是說,不要string,要String;不要int要Int32!至於為什麼,還是大家自己看看這本書吧,very useful!

http://www.free56.cn/post/43.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.