Domanda

Important edit: Do not use a Dictionary in this context. It uses Object.GetHashCode() which isn't good for use as a dictionary key. I still learned something from this though.

I have the following declaration

private static IDictionary<IDictionary<string,string>, IEnumerable<Fishtank>> _cache;

and the following code to attempt to initialize it

if (_cache == null) 
  _cache = new Dictionary<Dictionary<string,string>, LinkedList<Fishtank>>(); 

The problem I'm having is the initialization generates a compile time error.

Cannot implicitly convert type 'System.Collections.Generic.Dictionary,System.Collections.Generic.LinkedList>' to 'System.Collections.Generic.IDictionary,System.Collections.Generic.IEnumerable>'. An explicit conversion exists (are you missing a cast?)

I know that Dictionary and LinkedList implement IDictionary and IEnumerable respectively, so I'm at a bit of a loss here.

È stato utile?

Soluzione

you can do as below

if (_cache == null) 
    _cache = new Dictionary<IDictionary<string, string>, IEnumerable<Fishtank>>();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top