What is the parameter "in" in a generic type in C#?

Asked

Viewed 44 times

3

I came across a C# scenario that I didn’t quite understand. I was studying and I saw a code piece with a generic type that has the reserved word in for that guy.

What would be the purpose of using this in in the Generic Type declaration?

Code example:

public interface IHandler<in T> where T : Message
{
    void Handle(T message);
}
  • This article from Microsoft I think explains well what the in: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/in-generic-modifier

  • From what little I’ve read, it seems similar to super java

  • 1

    I guess that answers, doesn’t it? https://answall.com/q/32880/101. If not, give the context where you saw it.

  • Thanks @Joãomartins and @Maniero!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.