在计算机中存储数据和儿童在抽屉中存放物品很类似。
例如: 要在计算机中存一个数字50,需要两句话.
int a; //将要放的物品告诉家长
a=50; //将物品放到某个抽屉中
计算机存储变量的过程:
1.声明变量 2.给变量赋值 3.使用变量
数据类型:整数int 小数double 字符串string
*string类型变量可以看作是char类型变量的只读数组
字符编码规则(Character Encoding)构成→字符集(Charset)
练习:
{
//int a;
//int b = 1;
//a = b + 2;
//Console.WriteLine(a);
Console.WriteLine("变量的存储");
Console.WriteLine("整数int显示50");
//整数型int
int a;
a = 50;
Console.WriteLine(a);
Console.WriteLine("小数double显示3.14");
//小数型double
double b;
b = 3.14;
Console.WriteLine(b);
Console.WriteLine("int硬转小数型相加之和");
//小数型doubl相加及分别显示
int u;//求cdefg之和
int c =(int)13.1;//硬转变量int 小数前加(int)
int d = (int)14.1;
int e = (int)15.1;
int f = (int)16.1;
int g = (int)17.1;
u = c + d + e + f + g;
//double c, d, e, f, g;
//c = 13.1;
//d = 14.2;
//e = 15.3;
//f = 16.4;
//g = 17.5;
Console.WriteLine(u);//显示出c,d,e,f,g相加得结果
Console.WriteLine("int硬转小数型分别显示");
Console.WriteLine(c);
Console.WriteLine(d);
Console.WriteLine(e);
Console.WriteLine(f);
Console.WriteLine(g);//分别显示c,d,e,f,g\
Console.WriteLine("分别显示c d e f g并空格间隔");
Console.WriteLine(c + " " + d + " " + e + " " + f + " " + g);//分别显示c d e f g并空格间隔
Console.WriteLine("具体显示double类非硬转");
double h, i, j, k,l;
h= 13.1;
i = 14.2;
j = 15.3;
k= 16.4;
l = 17.5;
Console.WriteLine(h);
Console.WriteLine(i);
Console.WriteLine(j);
Console.WriteLine(k);
Console.WriteLine(l);
Console.WriteLine("显示非硬转double小数类hijkl相加之和");
Console.WriteLine(h+i+j+k+l);
Console.WriteLine("string字符串,可以看成是一个没有上限的存储");
//string字符串,可以看成是一个没有上限的存储
//char类型,它是一个0-2的16次方65536
string mystri中文= "你好";
string mystri字母 = "aBcDeFg";
string mystr012阿拉伯数字 = "0123456789";
string jiayou = "加油学编程努力为祖国";
Console.WriteLine(mystri中文);
Console.WriteLine(mystri字母);
Console.WriteLine(mystr012阿拉伯数字);
Console.WriteLine(jiayou);
Console.ReadKey();//等待字符
}