In c# what does 'where T : class' mean?

前端 未结 10 1967
太阳男子
太阳男子 2020-11-29 18:53

In C# what does where T : class mean?

Ie.

public IList DoThis() where T : class
10条回答
  •  独厮守ぢ
    2020-11-29 19:35

    it means that the type used as T when the generic method is used must be a class - i.e. it cannot be a struct or built in number like int or double

    // Valid:
    var myStringList = DoThis();
    // Invalid - compile error
    var myIntList = DoThis();
    

提交回复
热议问题