1

What different between IData< out T> and IData< T> ?

R.Titov
  • 3,115
  • 31
  • 35

1 Answers1

5

consider,

class Fruit {}

class Banana : Fruit {}

interface ICovariantData<out T> {}

interface IData<T> {}

and the functions,

void Peel(IData<Fruit> fruitData) { }

void Peel(ICovariantData<Fruit> fruitData) { }

The function that accepts ICovariantData<Fruit> will be able to accept ICovariantData<Fruit> or ICovariantData<Bananna> because it is a covariant interface and Banana is a type of Fruit,

the function that accepts IData<Fruit> will only be able to accept IData<Fruit>.

Jodrell
  • 34,946
  • 5
  • 87
  • 124