I wonder if it is possible to make the "dynamic" type for variables work for anonymous delegates.
I tried the following:
dynamic v = delegate() { };
But then I got the following error message:
Cannot convert anonymous method to type 'dynamic' because it is not a delegate type
Unfortunately, the following code does not work:
Delegate v = delegate() { }; object v2 = delegate() { };
What if I want to create a method that accepts any type of delegate, even built-in declared ones?
For instance:
class X{ public void Y(dynamic d){ } static void Main(){ Y(delegate(){}); Y(delegate(string x){}); } }
source share