Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where condition at runtime

Tags:

c#

linq

I have a code

 DataView res = (from a in dtvw.AsEnumerable()
                         where a.Field<string>(creteriaattributeID) == rightval
                        select a).AsDataView();

here , i wanna get the operator ("== ") at runtime is it possible ?

I tried using

where a.Field<string>(creteriaattributeID) + operator + rightval

operator --> string variable so it wont b possible ... Can you suggest any other methods...

like image 506
Abhijith Nayak Avatar asked Jun 19 '26 03:06

Abhijith Nayak


1 Answers

You can think of the == operator as function which takes two strings and return bool. So for example Func<string, string, bool>. Can you just use a variable of this type:

Func<string, string, bool> equal = (a,b) => { return a == b; };
Func<string, string, bool> notequal = (a,b) => { return a != b; };

DataView res = (from a in dtvw.AsEnumerable()
                where equal(a.Field<string>(creteriaattributeID), rightval)
                    select a).AsDataView();
like image 180
Petar Ivanov Avatar answered Jun 21 '26 15:06

Petar Ivanov