尝试在我的代码中调用此函数时,我得到了标题中的错误。同时,“+=”运算符无法应用于类型为“int”和“T”的操作数。
public int Change<T>(Stats type, T value)
{
Dictionary<string, string> temp = new Dictionary<string, string>();
temp = sql.Query(string.Format("SELECT {0} FROM player WHERE fbId='{1}'", type.ToString(), FBId));
if (typeof(T) == typeof(int))
{
int t = Convert.ToInt16(temp[type.ToString()]);
t += value;
if (t < 0) return -1;
PlayerStats[type] = t;
}
sql.Upload(string.Format("UPDATE player SET {0}='{1}' WHERE fbId='{2}'", type.ToString(), PlayerStats[type], FBId));
return 0;
}
我通过以下方式调用函数:
Change<int>(type, 1);