Cannot implicitly convert type 'T' to 'Int'

后端 未结 6 1809
轻奢々
轻奢々 2020-12-16 14:38

When trying to call this function in my code i get the error in the title. Also Operator \'+=\' cannot be applied to the operands of type \'int\' and \'T\'

p         


        
6条回答
  •  死守一世寂寞
    2020-12-16 15:23

    You can set constraint:

    public int Change(Stats type, T value) where T : IConvertible
    

    Then:

    var intValue = value.ToInt32();
    

提交回复
热议问题