C#中bool與Boolean有什麼區別?string和String區別?

來源:互聯網
上載者:User

轉自:http://hi.baidu.com/%CA%B8%C8%D0/blog/item/7d3392f883d4ecd5b48f31dc.html

1. bool是基本實值型別,Boolean 是對象.

2. bool是Boolean的別名.bool是C#中的,Boolean是.net Framework中的。

出於對Boolean的好奇,我用Reflector反組譯碼了下mscorlib.dll,得到Boolean的原始碼,看到了下面的內容:

public struct Boolean : IComparable, IConvertible, IComparable<bool>, IEquatable<bool>
    {
        private bool m_value;
        //省略其他成員的定義.....
     }

MSDN中解釋bool與Boolean的關係是:“bool 關鍵字是 System.Boolean 的別名”.實際使用無任何差別。它們的成員也是一樣的。
最後總結:bool就像你的乳名,你爹媽以及你們內部所屬成員都認識,Boolean就像你的學名。大家都認識。不過不管按照學名還是乳名稱呼你,最終的 目的是一樣的,還是你這個人。

對於String和string的關係也是如此。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.