C#編程概述

來源:互聯網
上載者:User

標籤:strong   大小   rar   變數   write   fixed   指令   包含   alt   

C#編程概述一個簡單的C#程式

標識符

標識符是一種字串,用來命名變數、方法、參數和許多後面將要闡述的其他程式結構。

關鍵字

所有C#關鍵字都由小寫字母組成,但是.NET類型名使用Pascal大小寫約定。


Main:程式的起始點
  • C#程式的可執行起始點在Main中第一條指令
  • Main首字母必須大寫
從程式輸出文本

BCL(Base Class Library,基底類別庫)提供Console類(在System命名空間中),該類包含了輸入和輸出資料到控制台的方法。 
Write

Console.Write("This is trivial text.");

 
WriteLine

System.Console.WriteLine("This is text1.");System.Console.WriteLine("This is text2.");System.Console.WriteLine("This is text3.");

 
格式字串

Console.WriteLine("Two sample integers are {0} and {1}.",3,6);

 
多重標記和值

Console.WriteLine("Three integers are {1},{0} and {1}.",3,6);

 
格式化數字字串

Console.WriteLine("The value:{0}.",500);Console.WriteLine("The value:{0:C}.",500);

對齊說明符

int myInt=500;Console.WriteLine("|{0,10}|",myInt);Console.WriteLine("|{0,-10}|",myInt);

格式欄位


double myDouble=12.345678;Console.WriteLine("{0,-10:G}--General", myDouble);Console.WriteLine("{0,-10}--Default,same as General", myDouble);Console.WriteLine("{0,-10:F4}--Fixed Point,4 dec places", myDouble);Console.WriteLine("{0,-10:C}--Currency", myDouble);Console.WriteLine("{0,-10:E3}--Sci.Notation,3 dec places", myDouble);Console.WriteLine("{0,-10:x}--Hexadecimal integer",1194719);

標準數字格式說明符


注釋

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.