Cannot implicitly convert type 'Int' to 'T'

前端 未结 9 2326
甜味超标
甜味超标 2020-11-27 14:15

I can call Get(Stat); or Get(Name);

But when compiling I get:

Cannot implicitly convert typ

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 14:36

    You should be able to just use Convert.ChangeType() instead of your custom code:

    public T Get(Stats type) where T : IConvertible
    {
        return (T) Convert.ChangeType(PlayerStats[type], typeof(T));
    }
    

提交回复
热议问题