Exemplo n.º 1
0
        static void Main(string[] args)
        {
            multi Multiply = (x, y) => x * y;

            Console.WriteLine(Multiply(2, 3));
            //Console.WriteLine("Hello World!");
        }
Exemplo n.º 2
0
 private void button3_Click(object sender, EventArgs e)
 {
     ingreso3    = new multi();
     ingreso3.M1 = double.Parse(textBox1.Text);
     ingreso3.M2 = double.Parse(textBox2.Text);
     label3.Text = ingreso3.calcular().ToString();
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // We are creating an instance of our delegate called lambda.
            // Here you can see the lambda operator => in action.
            // On the left side we have the arguments, in our case x
            // and on the right side we have the expression x + 1
            // You can notice that instead of creating a separate method for
            // incrementing of x by 1, we are using lambda expression here
            // and achieve the same with one line of code.

            lambda addOne = x => x + 1;

            Console.WriteLine(addOne(1)); // Output: 2
            Console.WriteLine("--------------");


            // We are creating an instance of our delegate called multi.
            // Once again, on the left side we have the arguments but this
            // time we have three(x,y,z) arguments. On the right side where we
            // put the expression, we are just multiplying them.

            multi multiply = (x, y, z) => x * y * z;

            Console.WriteLine(multiply(2, 3, 4)); //Output: 24
            Console.WriteLine("--------------");


            // We are creating an instance of our delegate caleld noparamsLambda.
            // You can see above that our delegate returns int but doesn.t have any
            // input parameters. That's the meaning of '() ' below. On the left side
            // you can see we have just empty paratheses.
            // Also note that on the right side we put a logic for a random number
            // generaor, the same way we are doing it in every normal method.

            noparamsLambda randomNumber = () =>
            {
                int random = new Random().Next();
                Console.WriteLine("Random number generated - {0}", random);
                return(random);
            };

            Console.WriteLine(randomNumber());
            Console.WriteLine("--------------");

            int[] firstTen = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            foreach (var num in firstTen)
            {
                Console.Write("{0} ", num);
            }
            Console.Write("\n");

            Console.WriteLine("Even numbers:");
            var even = firstTen.Where(n => n % 2 == 0);

            foreach (var num in even)
            {
                Console.Write("{0} ", num);
            }
            Console.Write("\n");
        }
Exemplo n.º 4
0
            //嘗試解析, 成功回傳 true, 並作成執行物件輸出到 obj
            //失敗回傳 false, obj 返回 null
            static public bool TryParse(string ln, out IRunnable obj)
            {
                //先把多餘的空白去掉
                string line = ln.Trim();

                //如果是空行就回傳一個空物件
                if (line.Trim() == "")
                {
                    obj = new empty();
                    return(true);
                }

                //從上層結構開始檢查, 這樣就保証層級關係的正確性
                //Parsing should begin from large scale structure to small scale structure
                //in order to ensure correct priority

                //單行指令可以是 loop, cond 或 multi
                if (IsLoop(line))
                {
                    obj = new loop(line);
                    return(true);
                }

                if (IsCond(line))
                {
                    obj = new cond(line);
                    return(true);
                }

                if (IsMulti(line))
                {
                    obj = new multi(line);
                    return(true);
                }


                obj = null;
                return(false);
            }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            lambda addOne = x => x + 1;

            Console.WriteLine(addOne(1)); // Output: 2
            Console.WriteLine("--------------");

            multi multiply = (x, y, z) => x * y * z;

            Console.WriteLine(multiply(2, 3, 4)); //Output: 24
            Console.WriteLine("--------------");

            noparamsLambda randomNumber = () => {
                int random = new Random().Next();
                Console.WriteLine("Random number generated - {0}", random);
                return(random);
            };

            Console.WriteLine(randomNumber());
            Console.WriteLine("--------------");

            int[] firstTen = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            foreach (var num in firstTen)
            {
                Console.Write("{0} ", num);
            }
            Console.Write("\n");

            Console.WriteLine("Even numbers:");
            var even = firstTen.Where(n => n % 2 == 0);

            foreach (var num in even)
            {
                Console.Write("{0} ", num);
            }
            Console.Write("\n");
        }
Exemplo n.º 6
0
            //嘗試解析, 成功回傳 true, 並作成執行物件輸出到 obj
            //失敗回傳 false, obj 返回 null
            public static bool TryParse(string ln, out IRunnable obj)
            {
                //先把多餘的空白去掉
                string line = ln.Trim();

                //如果是空行就回傳一個空物件
                if (line.Trim() == "")
                {
                    obj = new empty();
                    return true;
                }

                //從上層結構開始檢查, 這樣就保証層級關係的正確性
                //Parsing should begin from large scale structure to small scale structure
                //in order to ensure correct priority

                //單行指令可以是 loop, cond 或 multi
                if (IsLoop(line))
                {
                    obj = new loop(line);
                    return true;
                }

                if (IsCond(line))
                {
                    obj = new cond(line);
                    return true;
                }

                if (IsMulti(line))
                {
                    obj = new multi(line);
                    return true;
                }

                obj = null;
                return false;
            }
Exemplo n.º 7
0
 public cond(string line)
 {
     //提取條件和 multi
     condition = line.Split('?')[0];
     content = new multi(line.Replace(condition + "?", ""));
 }
Exemplo n.º 8
0
 public cond(string line)
 {
     //提取條件和 multi
     condition = line.Split('?')[0];
     content   = new multi(line.Replace(condition + "?", ""));
 }