fork download
  1. using System;
  2.  
  3. public class Test {
  4.  
  5. interface MyInterface { }
  6. delegate void MyFuncType<in InType>(InType input);
  7.  
  8. class MyClass<T> where T : MyInterface
  9. {
  10. public void callDelegate(MyFuncType<MyInterface> func)
  11. {
  12. MyFuncType<T> castFunc1 = (MyFuncType <T>) func; //Error
  13. MyFuncType<T> castFunc2 = func as MyFuncType<T>;
  14. MyFuncType<T> castFunc3 = func is MyFuncType<T> ? (MyFuncType<T>)func : (MyFuncType<T>)null; //Error
  15. }
  16. }
  17.  
  18. public static void Main()
  19. {
  20. Console.WriteLine("hello");
  21. }
  22. }
Success #stdin #stdout 0.02s 33680KB
stdin
Standard input is empty
stdout
hello