C# 4.0中dynamic的作用

   internal sealed class Coffee
{
public string GetName()
{
return "You selected Maxwell coffee.";
}
} internal sealed class Juice
{
public string GetName()
{
return "You selected orange juice.";
}
}
   internal sealed class DynamicDemo
{
public static void Main()
{ Console.WriteLine("Please Select Your Drink:1--Juice;2--Coffee"); var nDrinkRead = Console.Read(); dynamic drink = GetDrink(nDrinkRead); Console.WriteLine(drink.GetName()); Console.Read();
} private static object GetDrink(int i)
{
if (i == ) return new Juice();
return new Coffee();
}
}
上一篇:【poj3070】矩阵乘法求斐波那契数列


下一篇:用jQuery判断一个元素的各种状态