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

前端 未结 11 2239
不思量自难忘°
不思量自难忘° 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:56

    Use an abstract class instead. So, you would have something like:

    public bool Foo() where T : CBase;
    

提交回复
热议问题