C#系列之預留位置的使用方法(二)

來源:互聯網
上載者:User

標籤:複雜   line   ges   預留位置   images   write   方法   分享圖片   post   

 

今天,我將簡單記錄下預留位置的使用方法

首先,我們來看不使用預留位置的方法來代碼輸出

int number = 10;
int number_1 = 20;
int number_2 = 30;
Console.WriteLine("第一個數字是:" + number + "第二個數字是:" + number_1 + "第三個數字是:" + number_2);
Console.ReadKey();

輸出結果如:

這種方法使用+來串連,使得有些複雜化,容易出錯

下面,我將介紹使用預留位置的方法

預留位置:

使用方法:先挖個坑,再填個坑。

例如:

int number = 10;
int number_1 = 20;
int number_2 = 30;
Console.WriteLine("第一個數字是:{0},第二個數字是:{1},第三個數字是{2}",number,number_1,number_2 );
Console.ReadKey();

結果如:

可以發現,其結果和使用+號串連符一樣,但是,比他更快捷,簡單方便。

這裡再講一下使用方法

Console.WriteLine("第一個數字是:{0},第二個數字是:{1},第三個數字是{2}",number,number_1,number_2 );

第一個為0,然後依次加1

注意事項:挖啦幾個坑就填幾個坑,不要多填或者少填。

 

C#系列之預留位置的使用方法(二)

聯繫我們

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