c# - How to convert linq expression to dictionary<string,string> -


can me, how convert linq expression dictionary? following code throwing me argumentexception: item same key has been added.

        idictionary<string, string> listallcourseswithareaasdictionary = new dictionary<string, string>();          var dictionary =             (from b in booklistrecord              select new { b.coursecode, b.area }).distinct();          listallcourseswithareaasdictionary = dictionary.asenumerable().todictionary(x => x.coursecode, x => x.area);           return listallcourseswithareaasdictionary; 

when try this:

        listallcourseswithareaasdictionary = dictionary.asenumerable().todictionary(x => x.coursecode);  

i error: cannot implicitly convert type 'system.collections.generic.dictionary' 'system.collections.generic.idictionary'. explicit conversion exists (are missing cast?)

agreed aharon, you're looking grouping operator:

  var dictionary = booklistrecord     .groupby(g => g.coursecode)     .select(g => new { g.key,        arealist = g.select(c => c.area).tolist(),        area = g.select(c => c.area).firstordefault() })     .todictionary(g => g.key); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -