I’m having problems with calling a method that I have made.
The method I’m calling to is as folows
public bool GetValue(string column, out object result)
{
result = null;
// values is a Dictionary<string, object>
if (this._values.ContainsKey(column))
{
result = Convert.ChangeType(this._values[column], result.GetType());
return true;
}
return false;
}
I’m caling the method with the this code but I get an compiler error
int age;
a.GetValue("age", out age as object)
A ref or out argument must be an assignable variable
Does anyone else had this problem or am I just doing something wrong?
The variable needs to be exatly of the type specified in the method signature. You can’t cast it in the call.
The expression
age as objectis not an assignable value because it is an expression, not a storage location. For example, you cannot use it on the left hand of an assignment:If you want to avoid casting, you could try using a generic method:
Of course, some error checking should be inserted where appropriate)