🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
- 数据类型 bool 布尔值 True 或 False False byte 8 位无符号整数 0 到 255 0 char 16 位 Unicode 字符 U +0000 到 U +ffff '\0' decimal 128 位精确的十进制值,28-29 有效位数 (-7.9 x 1028 到 7.9 x 1028) / 100 到 28 0.0M double 64 位双精度浮点型 (+/-)5.0 x 10-324 到 (+/-)1.7 x 10308 0.0D float 32 位单精度浮点型 -3.4 x 1038 到 + 3.4 x 1038 0.0F int 32 位有符号整数类型 -2,147,483,648 到 2,147,483,647 0 long 64 位有符号整数类型 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 0L sbyte 8 位有符号整数类型 -128 到 127 0 short 16 位有符号整数类型 -32,768 到 32,767 0 uint 32 位无符号整数类型 0 到 4,294,967,295 0 ulong 64 位无符号整数类型 0 到 18,446,744,073,709,551,615 0 ushort 16 位无符号整数类型 0 到 65,535 0 ~~~ double[] balance = new double[10];声明数组十个元素 double[] balance = { 2340.0, 4523.69, 3421.0}; int [] marks = new int[] { 99, 98, 92, 97, 95}; int [][] scores; 交错数组,属于一维数组 string [,] names; 二维数组 int [ , , ] m; 三维数组 int [,] a = new int [3,4] { {0, 1, 2, 3} , /* 初始化索引号为 0 的行 */ {4, 5, 6, 7} , /* 初始化索引号为 1 的行 */ {8, 9, 10, 11} /* 初始化索引号为 2 的行 */ }; struct Books 结构体类型 { public string title; public string author; public string subject; public int book_id; }; enum Day { Sun, Mon, Tue, Wed, Thu, Fri, Sat }; 枚举类型 class Line{ private double length;私有方法 public void setLength( double len ) 可访问方法 { length = len; } static void Main(string[] args){} 静态方法 } class A:Line{} 继承类 interface IMyInterface 接口 { // 接口成员 void MethodToImplement(); } namespace namespace_name 命名空间 { // 代码声明 } object obj; 对象类型 dynamic d = 20; 动态类型,自动推断,可以是任何类型 String str = "runoob.com"; 字符串类型 string str = @"C:\Windows"; 不会转义 type* identifier; 指针类型 double d = 5673.74;d= (int)d; 类型转换 方法转换如下 1 ToBoolean 如果可能的话,把类型转换为布尔型。 2 ToByte 把类型转换为字节类型。 3 ToChar 如果可能的话,把类型转换为单个 Unicode 字符类型。 4 ToDateTime 把类型(整数或字符串类型)转换为 日期-时间 结构。 5 ToDecimal 把浮点型或整数类型转换为十进制类型。 6 ToDouble 把类型转换为双精度浮点型。 7 ToInt16 把类型转换为 16 位整数类型。 8 ToInt32 把类型转换为 32 位整数类型。 9 ToInt64 把类型转换为 64 位整数类型。 10 ToSbyte 把类型转换为有符号字节类型。 11 ToSingle 把类型转换为小浮点数类型。 12 ToString 把类型转换为字符串类型。 13 ToType 把类型转换为指定类型。 14 ToUInt16 把类型转换为 16 位无符号整数类型。 15 ToUInt32 把类型转换为 32 位无符号整数类型。 16 ToUInt64 把类型转换为 64 位无符号整数类型。 ~~~ - 变量和常量 ~~~ int d = 3, f = 5; const int c1 = 5; 常量 const string a = @"中国人"; ~~~ - 运算符 ~~~ + - * / ++ -- % == != > >= < <= += -= *= /= ?: && 与 || 或 !非 sizeof() 数据类型 typeof() class类型 &a 变量地址 *a 变量的指针 num3 = num1 ?? 5.34; 值为null时候取值,类似php ~~~ - 条件语句 ~~~ if(){ }else if(){ }else{ } switch (grade) { case 'A': Console.WriteLine("很棒!"); break; case 'B': case 'C': Console.WriteLine("做得好"); break; case 'D': Console.WriteLine("您通过了"); break; case 'F': Console.WriteLine("最好再试一下"); break; default: Console.WriteLine("无效的成绩"); break; } ~~~ - 循环 continue跳出当前执行下一条,break;退出 ~~~ while(condition) { } for (int a = 10; a < 20; a = a + 1) { Console.WriteLine("a 的值: {0}", a); } foreach (int element in fibarray) //数组或对象 { } ~~~