How to restrict T to value types using a constraint?

后端 未结 6 1818
情歌与酒
情歌与酒 2020-12-16 11:46

I want to restrict the possible types N can take-on using a constraint. I wish to restrict N to be either a int or a decimal.

public static Chart PopulateIn         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 11:48

    It's not possible to constrain a generic parameter to a specific value type.

    You can however force it to be a value type or struct by adding where N : struct, but that's all.

提交回复
热议问题