Can method parameters be dynamic in C#

后端 未结 4 1665
南旧
南旧 2020-12-30 19:39

In c# 4.0, are dynamic method parameters possible, like in the following code?

public string MakeItQuack(dynamic duck)
{
  string quack = duck.Quack();
  ret         


        
4条回答
  •  猫巷女王i
    2020-12-30 20:30

    Yes, you can do that. As stated in C# 4.0 specification, the grammar is extended to support dynamic wherever a type is expected:

    type:
           ...
          dynamic

    This includes parameter definitions, of course.

提交回复
热议问题