Saturday 28 October 2017

Anonymous method in C# Complete Guide from basic

example -1

 class Program
    {
        public delegate void Print(int value);
        static void Main(string[] args)
        {
            Print print = delegate(int val)
            {
                Console.WriteLine("Inside Anonymous method. Value: {0}", val);
            };

            print(100);
            print(2000);

            Console.ReadLine();
        }




    }

example -2

 class Program
    {
        public delegate void Print(int value);
        static void Main(string[] args)
        {
            int i = 10;

            Print prnt = delegate(int val)
            {
               // val += i;
                val = val + i;
                Console.WriteLine("Anonymous method: {0}", val);
            };

            prnt(100);

            Console.ReadLine();
        }
    }

example -3


  class Program
    {
        public delegate void Print(int value);
   
        static void Main(string[] args)
        {
            PrintHelperMethod(delegate(int val) 
            {
                Console.WriteLine("Anonymous method: {0}", val); 
            }, 100);

            Console.ReadLine();


        }

        public static void PrintHelperMethod(Print printDel, int val)
        {
            val += 10;
            printDel(val);
        }
    }

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...