2
public delegate TOutput Converter<in TInput, out TOutput>(TInput input)

What is the meaning of in and out in this declaration?

Harsh Baid
  • 7,199
  • 5
  • 48
  • 92
Alex F
  • 42,307
  • 41
  • 144
  • 212
  • You might want to [take a look here and read the article](http://msdn.microsoft.com/en-us/library/dd799517.aspx) about the covariance and contravariance in generics in C#. – Patryk Ćwiek Jun 12 '13 at 07:50
  • [Covariant and contra-variant](http://msdn.microsoft.com/en-us/library/dd799517.aspx) – cuongle Jun 12 '13 at 07:51
  • 1
    These are `Generic` modifiers. [`out (Generic Modifier)`](http://msdn.microsoft.com/en-us/library/dd469487.aspx) - [`in (Generic Modifier`)](http://msdn.microsoft.com/en-us/library/dd469484.aspx) – Soner Gönül Jun 12 '13 at 07:55

1 Answers1

2

Here's a great article from Eric Lippert's blog that explains the in and out keywords. They're used to express Covariance and Contravariance in generic type parameters.

What's the difference between covariance and assignment compatibility?

He also did a great 11 part series of articles on Covariance and Contravariance before it became a feature of C# 4. I'd highly recommend reading them as they will really help you grasp the concepts.

I've just checked and they're not linked to each other (and there's no easy way to just link to the series that I can find), so here's a table of contents.

Covariance and Contravariance in C#

Doctor Jones
  • 21,196
  • 13
  • 77
  • 99