I dont understand this error in C#.
error CS0236: A field initializer cannot reference the non-static field, method, or property 'Prv.DB.getUserName(long)'
public class MyDictionary<K, V>
{
//...
public delegate V NonExistentKey(K k);
NonExistentKey nonExistentKey;
public MyDictionary(NonExistentKey nonExistentKey_) { //...
}
}
class DB
{
SQLiteConnection connection;
SQLiteCommand command;
MyDictionary<long, string> usernameDict = new MyDictionary<long, string>(getUserName);
string getUserName(long userId)
{
command.CommandText = "SELECT name FROM userdata WHERE userId=@userId;";
command.Parameters.Add("@userId", DbType.Int64).Value = userId;
return (string)command.ExecuteScalar();
}
};