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);
标准数字格局说明符
注释 ,