int 有符号的32位整数(正负2的16次方) int age=77; short 有符号的16位整数 short a=11; long 有符号的64位整数 long gdp=70000000000L;//感觉不出来后面加L有什么差别 float 32位的浮点数,精确到小数点后7位 float b=1.7F; double 64位浮点数,精确到小数点后15~20位 double c=2D; decimal 128位浮点数,精确到小数点后28~29位 decimal d=5M; byte 8位无符号整数 bool 布尔型 string 字符序列 char 单个字符 常量关键字为 const
using System; public class Variable { //public const int intConst=11;//前面加修饰符public等时,不能放在函数里,只能放在类里。 public static void Main()//空间名、类名、方法函数都以大写字母开头,名字由各单词组成,各单词开头为大写字母;其他变量、常量、修饰符、关键字、数据类型等均为小写字母开头 {//部分变量测试 int intVar0;//申请的变量,程序没有用到,会被警告 int intVar = -2147483648;//负数可以到2的15次方,正数只能到2的15次方-1 short shortVar = -32768; long longVar = 9223372036854775807; long longVar1 = 900000000000000000L; Console.WriteLine("int value is{0},short value is{1},long value is{2},long value1 is{3}", intVar, shortVar, longVar, longVar1); Console.ReadLine(); float floatVar = 11.77F; double doubleVar = 11.77;//在数字后面可以加D,也可不加,也就是说一般情况下,小数点都是默认为double类型 decimal decimalVar = 11.77M; Console.WriteLine("floatVar is {0},double is {1},decimal is {2}", floatVar, doubleVar, decimalVar); Console.ReadLine(); float floatVar1 = -4294967296.1F; Console.WriteLine("floatVar1 is {0}", floatVar1);//为什么显示的不是全部数字,而是科学计数法, Console.ReadLine(); //部分常量测试 Console.WriteLine(intConst); Console.ReadLine(); const int intConst1 = 22; Console.WriteLine(intConst1); Console.ReadLine(); } public const int intConst = 11; }