C
C#•3y ago
?

Why Predicate contains in and parentheses?

Predicate<string> blahBlah = (string b) => b.Equals(b.ToUpper());
Predicate<string> blahBlah = (string b) => b.Equals(b.ToUpper());
As on the screenshot, this code is valid and I'm not doing something like <in string> and also there are no parentheses like Predicate<string>()
8 Replies
333fred
333fred•3y ago
The parentheses are part of defining a delegate type
333fred
333fred•3y ago
Delegates - C# Programming Guide
A delegate in C# is a type that refers to methods with a parameter list and return type. Delegates are used to pass methods as arguments to other methods.
333fred
333fred•3y ago
Variance in Delegates (C#)
Learn how the variance support in .NET allows you to match method signatures with delegate types in all delegates.
?
?OP•3y ago
So in the code should I use them or they're not present? Or there are different cases where I should put parentheses as well as in keyword? aniblobsweat
333fred
333fred•3y ago
Why do you think you need them?
?
?OP•3y ago
I dunno 😄 so there is no usage and I just put Predicate<int> wd; and that's it?
333fred
333fred•3y ago
Yes
?
?OP•3y ago
Alright, thanks for your help! dogohappy
Want results from more Discord servers?
Add your server