How to define generic type limit to primitive types?

后端 未结 5 1436
清歌不尽
清歌不尽 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:09

    You can use this to limit it to value types:

    where C: struct
    

    You also mention string. Unfortunately, strings won't be allowed as they are not value types.

提交回复
热议问题