I was reading about Action Delegate on MSDN and so this under syntax
public delegate void Action<in T>(T obj);
Than I looked in c-sharpcorner.com and it used this syntax
public delegate void Action<T>(T obj);
As you can see there is no in
before T.
Which syntax is right and what does that in
mean?
EDIT: The same syntax used for Predicate
.
Thanks.
Actions can only take input parameters, while Funcs can take input and output parameters. It is the biggest difference between them. An action can not return a value, while a func should return a value in the other words.
Action<T> Delegate (System)Encapsulates a method that has a single parameter and does not return a value.
Action is a delegate type defined in the System namespace. An Action type delegate is the same as Func delegate except that the Action delegate doesn't return a value. In other words, an Action delegate can be used with a method that has a void return type. For example, the following delegate prints an int value.
In English, a complete sentence or clause requires two parts: an action and the person or thing that's performing the action. While the subject describes who is doing the action, the predicate describes the action itself. Along with subjects, predicates are a necessary part of English sentence structure.
in
and out
(generic contravariance and covariance) were only introduced in C# 4, and the delegates and interfaces were modified for .NET 4 - so Action<T>
in .NET 3.5 became Action<in T>
in .NET 4.
The article you're referring to is from 2006, well before .NET 4 came out.
If you change which version of MSDN you're displaying, you'll see the change - for example, the .NET 3.5 version shows it without the in
.
The in
part is for covariance and contravariance and was introduced in .NET 4.0, the article you link to was published in 2006 before .NET 4.0 was released (so obviously it doesn't refer co[ntra]variance).
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