I have the following situation which is confusing me.
Given:
public class ThermoRawFile : MsDataFile { }
public abstract class MSDataFile { }
I am unable to run this LINQ IEnumerable.ToDictionary() method:
IEnumerable<string> rawFiles;
Dictionary<string, MSDataFile> dataFiles = rawFiles.ToDictionary(
file => file,
file => new ThermoRawFile(file)
);
as the compiler gives the following error:
"Cannot implicitly convert type System.Collections.Generic.Dictionary<string,CSMSL.IO.Thermo.ThermoRawFile> to System.Collections.Generic.Dictionary<string,CSMSL.IO.MSDataFile>"
Why cannot it implicit convert ThermoRawFile
into MSDataFile
when it is a simple inheritance?
This works just fine:
MSDataFile dataFile = new ThermoRawFile("someFile.raw");