Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
to figure out how to try to fill a comparison in my method.
I pass the lambda expression to the method via the parameter and then I try to compare it with the found value double.
C#
IndexMax(mapPointList, seznamIndex, point => point.X);

C#
private void IndexMax(List<MapPoint> mapPointList, List<int> seznamIndex, Func<MapPoint, double> lambda)
        {
            double hodnotaMax = mapPointList.Max(lambda);
            int index = mapPointList.FindIndex(lambda == hodnotaMax);//Error	CS0019	Operator '==' cannot be applied to operands of type 'Func<MapPoint, double>' and 'double'	
            seznamIndex.Add(index);
        }


What I have tried:

How can I write a value so that it can be applied?

Thank you

David
Posted
Updated 9-Jun-22 2:47am
v2
Comments
Richard MacCutchan 9-Jun-22 5:15am    
You have not explained what is wrong with the original code and what you are trying to change.
dejf111 9-Jun-22 5:26am    
Now that everything is fine, I just want to shorten the code.
Richard MacCutchan 9-Jun-22 5:43am    
Shorten it to what?
dejf111 9-Jun-22 5:45am    
It is stated there.
dejf111 9-Jun-22 8:30am    
I remade the question

1 solution

You need your Func to actually do something, you cannot use it to compare against a simple type. See Func<T,TResult> Delegate (System) | Microsoft Docs[^].
 
Share this answer
 
Comments
dejf111 10-Jun-22 1:09am    
Thanks, I'm still not smart about it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900