asp.net mvc - Convert list<object> list to dictionary from linq to sql query results c# -
im trying convert results of ling sql select results dictionary.
when this:
var dict = new dictionary<string, string>(); var encodedcontent = new formurlencodedcontent(dict);
id accepts dictionary no issues.
when this:
var dict = leads .select((s, i) => new { s, }) .todictionary(x => x.i, x => x.s) .getenumerator(); var encodedcontent = new formurlencodedcontent(dict);
i error:
severity code description project file line suppression state error cs1503 argument 1: cannot convert
system.collections.generic.dictionary<int,postleadstoclient.models.educatorlead>.enumerator
system.collections.generic.ienumerable<system.collections.generic.keyvaluepair<string, string>>
postleadstoclient c:\rgi projects\postleadstoclient\postleadstoclient\program.cs 159 active
i cannot live of me figure out doing wrong.
im convert results of query wrong?
remove getenumerator()
query since want dictionary.
the error message tells you pass enumerator desired type ienumerable<keyvaluepair<string, string>>
dictionary<string, string>
implements.
so should work (note use x.i.tostring()
because i
int
):
var dict = leads .select((s, i) => new { s, }) .todictionary(x => x.i.tostring(), x => x.s); // note tostring var encodedcontent = new formurlencodedcontent(dict);
Comments
Post a Comment