Example #1
0
        public void Lambdas()
        {
            // lambda - simplified writting of anon method;
            //
            OperLam operLam  = (x, y) => x + y;
            OperLam operLam1 = (x, y) => { Console.WriteLine(""); return(x + y); };
            //var lam = (x, y) => x + y; -> cannot assign lambda to implicitly typed variable
            Squere   squere  = x => x * x;                       // brackets in parameters can be ommitted if one param;
            HelloLam hello   = () => Console.WriteLine("hello"); // empty brackets if no params;
            Handler  handler = (ref int i) => i = i * 2;         // type has to be put in brackets if ref ot out modifiers
            HelloLam hello1  = () => Show_M();                   // lambdas can make other methods

            // lmbdas can be passed as params to methods:
            var nums = ChangeNumbers(new List <int>()
            {
                1, 2, 3, 4
            }, i => i + 10);
        }
Example #2
0
 public static int CalculateArea(Squere squere)
 {
     return squere.Height * squere.Height;
 }