占位符
using System;
namespace Day2
{
class Program
{
static void Main(string[] args)
{
string name1 = "001";
string name2 = "002";
// 占位符
string str = string.Format("name1:{0},name2:{1}", name1, name2);
Console.WriteLine(str);
// 标准数字格式字符串
Console.WriteLine("金额:{0:c}",10); //货币 ¥10.00
Console.WriteLine("{0:d2}",5); // 05 指定精度填充
Console.WriteLine("{0:f1}",1.26); // 1.3 指定精度显示
Console.WriteLine("{0:p0}",0.1); // 10% 百分数显示
Console.WriteLine("{0:p}",0.1); // 10.00%
// 转义符
Console.WriteLine("我爱\"China\""); // 我爱"China"
char c1 = '\''; // '
char c2 = '\0'; // 空字符
Console.WriteLine("你好,\r\n我是\tAdolph"); // \r\n回车换行 \t tab
}
}
}
.NET程序编译过程
源代码(.cs的文本文件)->CLS编译->通用中间语言(.exe.dll)->CLR编译->机器码
目的:跨语言 CIL 目的:优化 跨平台
公共语言规范Common Language Specification 公共语言运行库CL Runtime
运算符
++1 先加,该步骤先进行
1++ 后加,该步骤后进行
数据类型转换
using System;
namespace Day2
{
class Program
{
static void Main(string[] args)
{
// 1.Parse转换:string转换为其他数据类型
string strNumber = "18";
int num01 = int.Parse(strNumber);
float num02 = float.Parse(strNumber);
// 2.ToString转换:任意类型转换为string类型
int number = 18;
string str = number.ToString();
}
}
}
# region 注释说明
...方便折叠
# endregion
if() {} else if() {} else{}
switch() {case : break; ...... default: break;}