Why Predicate contains in and parentheses?
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
The parentheses are part of defining a delegate type
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.
The
in
is variance: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/covariance-contravariance/variance-in-delegatesVariance in Delegates (C#)
Learn how the variance support in .NET allows you to match method signatures with delegate types in all delegates.
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? Why do you think you need them?
I dunno 😄 so there is no usage and I just put
Predicate<int> wd;
and that's it?Yes
Alright, thanks for your help!