C#中的数据类型:
1、整型
sbyte、short、int、long
sbyte:-128~127;
short:短整型;
int:整形;
long:长整形;
2、浮点型
float:单精度,精确到后7位
float a = 3.4;//错误,因为3.4默认为double,不能赋给float
float a = 3.2f;// 正确
double:双精度,精确到小数点后15位
3、字符型
char:字符型,单个字符
string:字符串类型
char c = "q";
string d= "hello 中国";
4、布尔型
bool:值只有true 和false 两种;
二、基本运算
字符串相加相当于字符串的拼接;
三、数组定义
第一种方法:
数组定义:类型[] 数组名={};
int[] a = {1,2,3,4};
查看数据从0开始 a[0]
第二种方法:
int[] a = new int[10];
这种方法下,a中所有元素都被赋初值 0 ;
第三种方法:
int[] a = new int[] { 1,2,3,4,5}; //定义同时初始化;注意第一个[]内不能存在数字