locked
Func<T,TResult> delegate RRS feed

  • Question

  • Hi,

    Is it possible to declare a Func<T,TResult> delagate in an interface or can it only be declared in a Class?

     

    Tuesday, October 11, 2011 9:10 PM

Answers

  • You cannot have generic properties in an interface unless they use the same type parameter of the interface itself. Therefore, the following is not allowed:

    // Not allowed:
    public interface Foo {
      Func<T, TResult> Bar { get; set; }
    }
    

    but you can have:

    // Allowed:
    public interface Foo<T, TResult> {
      Func<T, TResult> Bar { get; set; }
    }
    

    HTH
    --mc

    • Proposed as answer by Bob Wu-MT Wednesday, October 12, 2011 5:52 AM
    • Marked as answer by Bob Wu-MT Tuesday, October 25, 2011 9:25 AM
    Tuesday, October 11, 2011 9:37 PM