I've a collection of notes. Depending on the UI requesting those notes, I'd like to exclude some categories. This is just an example. If the project Notes popup requests notes, I should exclude collection notes.
Func<Note, bool> excludeCollectionCategory = (ui == UIRequestor.ProjectNotes)
? x => x.NoteCategory != "Collections"
: x => true; //-- error: cannot convert lambda to lambda
I'm getting the following error: Type of conditional expression cannot be determined because there is no implicit conversion between 'lambda expression' and 'lambda expression'
Thanks for helping
The compiler doesn't infer delegate types for lambda expressions. You need to specify the delegate type using a cast in the first ternary clause:
var excludeCollectionCategory = (ui == UIRequestor.ProjectNotes)
? (Func<Note, bool>)(x => x.NoteCategory != "Collections")
: x => true;
The silver lining is that you can use var
instead of having to specify the type for the variable, so it isn't that much more verbose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With