1.作用域问题
string text = ""; //这里必需初始化
for (int i = 0; i < maxArray.Length; ++i) {
text = "hello text" + i;
}
Console.WriteLine(text);
2. switch case 必须加break
3. int[][] array //锯齿数据 与 int[,] array 区别
int[][] array3 = {new int[] {1},
new int[] {2, 3},
new int[] {7, 8, 9}
};
int[,] array2 = { { 1, 2, 3 }, { 4, 5, 6 } };
4. 枚举类型
enum orientation : int {
north = 20,
south,
east,
west = 4
}
Console.WriteLine("{0}, {1}", (byte)ori, Convert.ToString(ori));
string north = "north";
orientation nor = (orientation)Enum.Parse(typeof(orientation), north);
Console.WriteLine("{0}", (int)nor);
5.string
string padleft = " hello";
char[] ch = padleft.ToCharArray();
Console.Write("{0}, {1}", ch.Length, padleft.Length);
Console.WriteLine(padleft.Trim());
Console.WriteLine(padleft.TrimEnd());
Console.WriteLine(padleft.PadLeft(10));
6. foreach (int arr in arrlist) {
}
7.delegate ==>函数指针
static double mul(double a, double b)
{
return a * b;
}
static double div(double a, double b)
{
return a / b;
}
delegate double process(double param1, double param2);
process proc;
double p1 = 10.0;
double p2 = 2.5;
string input = Console.ReadLine();
if (input == "M") {
proc = new process(mul);
} else {
proc = new process(div);
}
Console.WriteLine(proc(p1, p2));
8.参数修饰符 params : 变元必须是参数列表的最后一个
ref : 引用类型
out : 返回值类型
static void para(int k, params int[] arr)
{
Console.WriteLine("长度 = " + arr.Length);
}
int[] array = {1, 2, 3};
para(4, array);
paraWithOut(4, out array);
parawithRef(4, ref array);
string text = ""; //这里必需初始化
for (int i = 0; i < maxArray.Length; ++i) {
text = "hello text" + i;
}
Console.WriteLine(text);
2. switch case 必须加break
3. int[][] array //锯齿数据 与 int[,] array 区别
int[][] array3 = {new int[] {1},
new int[] {2, 3},
new int[] {7, 8, 9}
};
int[,] array2 = { { 1, 2, 3 }, { 4, 5, 6 } };
4. 枚举类型
enum orientation : int {
north = 20,
south,
east,
west = 4
}
Console.WriteLine("{0}, {1}", (byte)ori, Convert.ToString(ori));
string north = "north";
orientation nor = (orientation)Enum.Parse(typeof(orientation), north);
Console.WriteLine("{0}", (int)nor);
5.string
string padleft = " hello";
char[] ch = padleft.ToCharArray();
Console.Write("{0}, {1}", ch.Length, padleft.Length);
Console.WriteLine(padleft.Trim());
Console.WriteLine(padleft.TrimEnd());
Console.WriteLine(padleft.PadLeft(10));
6. foreach (int arr in arrlist) {
}
7.delegate ==>函数指针
static double mul(double a, double b)
{
return a * b;
}
static double div(double a, double b)
{
return a / b;
}
delegate double process(double param1, double param2);
process proc;
double p1 = 10.0;
double p2 = 2.5;
string input = Console.ReadLine();
if (input == "M") {
proc = new process(mul);
} else {
proc = new process(div);
}
Console.WriteLine(proc(p1, p2));
8.参数修饰符 params : 变元必须是参数列表的最后一个
ref : 引用类型
out : 返回值类型
static void para(int k, params int[] arr)
{
Console.WriteLine("长度 = " + arr.Length);
}
int[] array = {1, 2, 3};
para(4, array);
paraWithOut(4, out array);
parawithRef(4, ref array);