user3085995
user3085995

Reputation: 453

how to check compare variable in LINQ where condition

i'm getting some value inside a variable and i want to compare it inside my LINQ query. i tried following,

string var_name = Convert.ToString(res[2]);

var result = from p in listData
             where p.cd == var_name
             select p;

but getting error Embedded statement can not be a declaration or labeled statement

Upvotes: 0

Views: 625

Answers (1)

Kaspars Ozols
Kaspars Ozols

Reputation: 7017

Are you sure that this is connected to LINQ?

Error Embedded statement can not be a declaration or labeled statement usually means that you are doing something like this:

//WRONG:
if (true)
    int i=5;
i++;

In that case you have to change it to:

//CORRECT
if (true)
{
    int i=5;
    i++;
}

Upvotes: 2

Related Questions