What does the keyword “where” in a class declaration do?

前端 未结 7 1145
天涯浪人
天涯浪人 2020-12-17 17:24

I\'m looking at the source code for the MvcContrib Grid and see the class declared as:

public class Grid : IGrid where T : class

相关标签:
7条回答
  • 2020-12-17 18:27

    Another examples would be

    public A<T> where T : AnInterface
    

    where AnInterface is a interface class. It means then, that T must implement this interface.

    These constraints are important, so that the compiler knows the operations which are valid for the type. For example you can not call functions of T without telling the compiler what functions the type provides.

    0 讨论(0)
提交回复
热议问题