How to define generic type limit to primitive types?

后端 未结 5 1401
清歌不尽
清歌不尽 2020-12-03 00:13

I have the following method with generic type:

T GetValue();

I would like to limit T to primitive types such as int, string, float

5条回答
  •  無奈伤痛
    2020-12-03 01:00

    What are you actually trying to do in the method? It could be that you actually need C to implement IComparable, or someother interface. In which case you want something like

    T GetObject where T: IComparable
    

提交回复
热议问题