How can I use interface as a C# generic type constraint?

前端 未结 11 2238
不思量自难忘°
不思量自难忘° 2020-11-27 12:27

Is there a way to get the following function declaration?

public bool Foo() where T : interface;

ie. where T is an interface type

11条回答
  •  天命终不由人
    2020-11-27 12:54

    I know this is a bit late but for those that are interested you can use a runtime check.

    typeof(T).IsInterface
    

提交回复
热议问题