note--基本语法(1)

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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值