Blog Stats
  • Posts - 148
  • Articles - 0
  • Comments - 92
  • Trackbacks - 14

 

Generics

There are 1 entries for the tag Generics

C# generics - parameter variance, its constraints and how it affects WCF

CLR generics are great and there is no doubt about that. Unfortunately, C# doesn't expose the whole beauty of it because all generic type parameters in C# are nonvariant though from CLR point of view they can be marked as nonvariant, covariant or contravariant. You can find more details about that topic here and here. In short the "nonvariant" word means that even though type B is a subtype of type A then SomeType<B> is not a subtype of SomeType<A> and therefore the following code won't compile: 1 List<String> stringList = null; 2 List<object> objectList = stringList;  <--  this...

 

 

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Copyright © Pawel Pabich