Wednesday, 23 September 2015

real world use of dynamic in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using Moq;

namespace DynamicKeyword
{
    public class Base
    {
        public void foo(int x) { Console.WriteLine(x); }
    }
    public class Derived : Base
    {
        public void foo(string x) { Console.WriteLine(x); }
    }
    class Program
    {
        static void Main(string[] args)
        {

            dynamic baseclass = new Derived();
            dynamic d = "4";
            dynamic c=1;
            baseclass.foo(d);
            baseclass.foo(c);
            //new StaticTester().Call();
            //new ReflectiveTester().Call();
            //new DynamicTester().Call();
            Console.ReadKey(false);
        }
    }

}

No comments:

Post a Comment