dynamic类型,.net命名参数,可选参数列表

直接上代码:
using System;
using System.Collections.Generic;
using System.Text;

namespace DynamicDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            dynamic dyn;
            object obj;
            dyn = 2;
            obj = 3;

            Console.WriteLine(dyn.GetType());
            Console.WriteLine(obj.GetType());

            dynamic output=Result(count:14,name:"hell");

            Console.WriteLine(output);

            output = Result(count: "NNN", name: "kaokaokao");
            Console.WriteLine(output);
            Console.ReadKey();
        }

        static dynamic Result(dynamic count, string name = "fang wei")
        {
            string str = "hello word";
            int y = 4;
            if (count is int)
            {
                return count + y;
            }
            else
            {
                return str + name;
            }

        }
    }
}

你可能感兴趣的:(dotNet4.0,New!)