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

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

    No, actually, if you are thinking class and struct mean classes and structs, you're wrong. class means any reference type (e.g. includes interfaces too) and struct means any value type (e.g. struct, enum).

提交回复
热议问题