当试图在我的代码中调用此函数时,我在标题中出现错误。也算“+ =”不能应用于类型“诠释”的操作数和“T”无法将类型'T'隐式转换为'Int'
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);
如果这个方法不是通用的,这个方法是通用的吗? – dlev
如此明确地转换它? –
Bobby Tables不会破坏您的数据库,您有多自信? –