运算符
@"" 定义字符串
& 返回变量的地址
* 变量的指针
? : 条件表达式
is 判断对象是否为某一类型
as 强制转换,即使转换失败也不会抛出异常
sealed 类不能被继承
typeof() 返回 class 的类型
ref 强直传引用 public void swap(ref int x, ref int y)
out 输出参数 输出参数会改变自己的值 public void getValue(out int x )
//可空类型 Nullable 可为该变量正常值,亦可为null
int? num1 = null;
int? num2 = 45;
double? num3 = new double?();
double? num4 = 3.14157;
bool? boolval = new bool?();
//合并运算符 ?? 左操作数为null,则赋右操作数
double? num1 = null;
double? num2 = 3.14157;
double num3;
num3 = num1 ?? 5.34;
num3 = num2 ?? 5.34;
数组
int[] arr= new double[10];
int[] arr= {99,98,92,97,95};
int[] arr= new int[] {99,98,92,97,95};
int[] arr= new int[5] {99,98,92,97,95};
foreach (int i in arr){
Console.WriteLine(i);
}
int[,] a;//二维数组
int[,,] a;//三位数组
int [,] a = new int [3,4] {
{0, 1, 2, 3} , /* 初始化索引号为 0 的行 */
{4, 5, 6, 7} , /* 初始化索引号为 1 的行 */
{8, 9, 10, 11} /* 初始化索引号为 2 的行 */
};
//好久没用了
int[][] scores = new int[2][]{new int[]{92,93,94},new int[]{85,66,87,88}};
public int AddElements(params int[] arr){
int sum = 0;
foreach (int i in arr){
sum += i;
}
return sum;
}
int[] temp = { 34, 72, 13, 44, 25, 30, 10 };
Array.Reverse(temp);
Array.Sort(temp);
字符串
string[] sarray = { "Hello", "From", "Tutorials", "Point" };
string message = String.Join(" ", sarray);
复杂结构
enum Days {
Mon=71,
tue=61,
Wed=51,
thu=41,
Fri=51,
Sat=61,
Sun=71
};
enum Days {
Mon=71,
tue, //72
Wed, //73
thu=41,
Fr, //42
Sat,
Sun
};
enum Days {
Mon, //0
tue,//1
Wed, //2
thu,
Fr,
Sat,
Sun
};