0

In C# can you do something like

Func<typeof(variableType),int)> myDelegate;

where you can pass the type arguments dynamically to a delegate?

Shiva
  • 20,575
  • 14
  • 82
  • 112
wootscootinboogie
  • 8,461
  • 33
  • 112
  • 197

2 Answers2

1

You can not use Func<typeof(variableType),int)> myDelegate;.and get syntax error.

Use:

        Func<object,int> myDelegate;

or:

        Func<dynamic,int> myDelegate;

And see this:Generating Delegate Types dynamically in C#

Community
  • 1
  • 1
1

No. typeof() is evaluated at run-time. Your delegate declaration is evaluated at compile time. The typeof() evaluation would have to occur first for this to work.

Yes - that Jake.
  • 16,725
  • 14
  • 70
  • 96