Search code examples
c#.neterror-handling

A property or indexer may not be passed as an out or ref parameter


I'm getting the above error and unable to resolve it. I googled a bit but can't get rid of it.

Scenario:

I have class BudgetAllocate whose property is budget which is of double type.

In my dataAccessLayer,

In one of my classes I am trying to do this:

double.TryParse(objReader[i].ToString(), out bd.Budget);

Which is throwing this error:

Property or indexer may not be passed as an out or ref parameter at compile time.

I even tried this:

double.TryParse(objReader[i].ToString().Equals(DBNull.Value) ? "" : objReader[i].ToString(), out bd.Budget);

Everything else is working fine and references between layers are present.


Solution

  • you cannot use

    double.TryParse(objReader[i].ToString(), out bd.Budget); 
    

    replace bd.Budget with some variable.

    double k;
    double.TryParse(objReader[i].ToString(), out k); 
    bd.Budget = k;