Example #1
0
        static void Main(string[] args)
        {
            int age = 22;
            //int outVal;
            int a = 3;

            int[,] arr = new int[5, 2] {
                { 0, 0 }, { 1, 2 }, { 2, 5 }, { 3, 8 }, { 7, 9 }
            };
            FillValues();
            Console.WriteLine("Ref Eg: " + RefAndOut.Test(ref age));
            Console.WriteLine("Normal Eg: " + RefAndOut.Test1(10));
            Console.WriteLine("Out Eg: " + RefAndOut.Test2(out age));
            Console.WriteLine("in Eg: " + RefAndOut.Test3(in a));
            Console.WriteLine("--------Twodimentional array");
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Console.WriteLine($"a[{i},{j}] = {arr[i,j]}");
                }
            }
            Console.WriteLine("-------Yield Example-------");
            foreach (var item in Filter())
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("-------Yield Running Total-------");
            foreach (var item in RunningTotal())
            {
                Console.WriteLine(item);
            }

            Console.Read();
        }
Example #2
0
        static void Main(string[] args)
        {
            int outVal = 2;

            Console.WriteLine("Final Value without ref :" + RefAndOut.Test1(22));
            Console.WriteLine("Final Value with out :" + RefAndOut.Test3(out outVal));
            Console.WriteLine("Final Value with in : " + RefAndOut.Test4(10));


            int age = 10;
            int res = RefAndOut.Test(ref age);

            Console.WriteLine($"Final Output : {res}");
            Console.WriteLine("Final Output : " + res);
            Console.ReadLine();

            //ref keyword passes arguments by reference. This means
            //any changes made to this argument or parameter in the method
            //will be reflected in the variable of the calling method
        }