C#编程概述

Posted on 2018-02-06 14:45  阳光下的约定&  阅读(204)  评论(0编辑  收藏  举报

 

一个简单的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);

 

 

标准数字格式说明符

注释

 

 

 


 


 


 


 

Copyright © 2024 阳光下的约定&
Powered by .NET 8.0 on Kubernetes