Al intentar llamar a esta función en mi código, aparece el error en el título. También operador '+ =' No se puede aplicar a los operandos de tipo 'int' y 'T'No se puede convertir implícitamente el tipo 'T' a '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;
}
que llame a la función mediante el uso de:
Change<int>(type, 1);
¿De qué sirve hacer que este método sea genérico si no es genérico? – dlev
así que conviértalo explícitamente? –
¿Qué tan seguro está de que Bobby Tables no arruine su base de datos? –