[Mono-list] Converting list types

Jonathan Pryor jonpryor at vt.edu
Tue Mar 6 19:28:16 EST 2007


On Tue, 2007-03-06 at 23:46 +0000, Chris Seaton wrote:
> gmcs says that it
> 
> Cannot convert from  
> `System.Collections.Generic.List<Katahdin.Grammars.ParseGraphNode>'  
> to `System.Collections.Generic.List<Katahdin.Grammars.IParseable>'
> 
> ParseGraphNode implements IParseable, so I would have thought that  
> the compiler would allow that, but since it doesn't, what is the best  
> way to convert from List<InterfaceImplementation> to List<Interface>?  
> I know I can instantiate a new List<Interface> and copy one by one  
> into that, but it seems a very common operation - is there a shortcut?

I assume you're trying to do this:

	void Foo (List<IParseable> list) {...}

	List<ParseGraphNode> c = ...;
	Foo (c);

The simple solution is to make Foo() itself generic:

	void Foo<T> (List<T> list) where T : IParseable {...}

 - Jon




More information about the Mono-list mailing list