Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ, Lambda, C#, extension methods

I've only been playing with linq to sql and lambda expressions for the first time for a few days and I want to do the following.

I've got a string extension method that returns a double. The extension method tests two strings and returns a similarity score. I have a list of string values from a column in a table using linq to sql and I want to use the extension method as a way of filtering out the only those strings whose similarity score is equal to or greater than the input string.

I've got the below so far. I don't seem to be able to test the value of the returned double.

List<int> ids = dc.ErrorIndexTolerances
                  .Where(n => n.Token.Distance(s) => .85)
                  .Select(n => n.ID)
                  .ToList();

The Distance Method is the extension method that returns a double. Both Token and s are string. ID is an integer ID field within a table.

Does anyone have any tips?

like image 210
zeencat Avatar asked Jul 20 '26 18:07

zeencat


2 Answers

The greater or equal operator is >=, not =>.

List<int> ids =
  dc.ErrorIndexTolerances.Where(n => n.Token.Distance(s) >= .85)
  .Select(n => n.ID).ToList();
like image 175
Guffa Avatar answered Jul 23 '26 08:07

Guffa


Perhaps this should be

n.Token.Distance(s) >= .85) 

Just a typo :-)

like image 36
Steve Avatar answered Jul 23 '26 06:07

Steve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!