Quando si tenta di chiamare questa funzione nel mio codice ottengo l'errore nel titolo. Anche l'operatore '+ =' non può essere applicato a operandi di tipo 'int' e 'T'Impossibile convertire implicitamente il tipo 'T' in '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;
}
chiamo la funzione utilizzando:
Change<int>(type, 1);
Qual è lo scopo di rendere questo metodo generico se non è generico? – dlev
quindi convertirlo in modo esplicito? –
Quanto sei sicuro che Bobby Tables non distrugga il tuo database? –