Question about C# 2.0 generics

A

A.M-SG

Hi,



The following code gives me InvalidCastException with the following message:



{"Unable to cast object of type 'System.Collections.Generic.List`1' to type
'System.Collections.Generic.IList`1'."}



What is the reason?



Any help would be appreciated,

Alan







public OracleDatabase ELOracleDatabase

{

get

{

if (_ELOracleDatabase == null)

{



// ****************************

// InvalidCastException happens here!

IList<IOraclePackage> oraclePackages =
(IList<IOraclePackage>)(new List<OraclePackage>());



_ELOracleDatabase = new OracleDatabase(_connectionString,
null);



}

return _ELOracleDatabase;



}



}



class OraclePackage : IOraclePackage

{

string _name, _prefix;

OraclePackage()

{

_name = string.Empty;

_prefix = string.Empty;

}

public string Name

{

get { return _name; }

set { _name = value; }

}

public string Prefix

{

get { return _prefix; }

set { _prefix = value; }

}

}



public interface IOraclePackage

{

string Name

{ get; }

string Prefix

{ get; }

}
 
C

Christof Nordiek

'IList<IOraclePackage>' is not a basetype of 'List<OraclePackage>()'
that's all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top