C#中String與string的區別分析

來源:互聯網
上載者:User

標籤:width   like   div   ffffff   lock   同步   影像處理   聲明變數   get   

本文執行個體展示了C#程式設計中String與string的區別,對於C#初學者來說有很好的參考借鑒價值。具體如下:


一、區別分析:


String:類,System.String


string:類型,變數

兩者本質上沒有任何區別,都是System.String,string只是System.String的別名而已

唯一的區別在於如何按照代碼約定的來寫,

如聲明變數時使用小寫string,使用System.String下方法時使用大寫的String


二、範例程式碼如下:

class Program{  static void Main(string[] args)  {    /*在代碼使用上沒有任何區別 在使用規範上需要看下是否符合代碼約定的規範*/    Console.WriteLine(typeof(string));    Console.WriteLine(typeof(String));    string name1 = "Gerry 1";    String name2 = "Gerry 2";    Console.WriteLine(name1);    Console.WriteLine(name2);    Console.WriteLine(string.Concat(name1, name2));    Console.WriteLine(String.Concat(name1, name2));    Console.ReadLine();    Console.ReadLine();  }}

程式運行結果如所示:

除聲明外, 跑步客文章均為原創,轉載請以連結形式標明本文地址
  C#中String與string的區別分析

本文地址:  http://www.paobuke.com/develop/c-develop/pbk23623.html






相關內容C#使用AutoResetEvent實現同步淺談c#運算式樹狀架構Expression簡單類型比較demoC#實現自動識別URL網址的方法C#影像處理之浮雕效果實現方法
C#中Activator.CreateInstance()方法用法分析C#實現的圖片、string相互轉換類分享C#實現根據年份計算生肖屬相的方法C#不可變類型深入解析

C#中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.