[Mono-list] Generics Conversions

Robert Jordan robertj at gmx.net
Mon Feb 23 08:23:31 EST 2009


Sascha Leib wrote:
> Hello all,
> 
> I noticed one behaviour when using Generics:
> 
>             List<String> StringList = new List<String>();
> 
>             List<Object> ObjectList = (StringList as List<Object>);  //
> Error
> 
> The error message is:
>     Program.cs(14,51): error CS0039: Cannot convert type
> `System.Collections.Generic.List<string>' to
> `System.Collections.Generic.List<object>' via a built-in conversion
> 
> Is that a wanted behaviour? Or am I missing something? This really stops
> me from using more Generics at the moment :-/

An explication:

http://jopinblog.wordpress.com/2007/10/26/c-generic-covariance/

Robert



More information about the Mono-list mailing list