Joining IEnumerable <KeyValuePair <string, string >> values ββinto a string using Linq
Given IEnumerable<KeyValuePair<string,string>> , I'm trying to use linq to concatenate values ββinto one string.
My attempt:
string path = attributes.Aggregate((current, next) => "@" + current.Key + "=" + current.Value + " and @" + next.Key + "=" + next.Value); This results in an error:
Cannot convert expression type '
string' to return type 'KeyValuePair<string,string>'
Is there a more efficient way to do this in linq?
Full method ...
public IEnumerable<XmlNode> GetNodes(IEnumerable<KeyValuePair<string,string>> attributes) { StateInfoXmlDocument stateInfoXmlDocument = new StateInfoXmlDocument(); string path = attributes.Aggregate((current, next) => "@" + current.Key + "=" + current.Value + " and @" + next.Key + "=" + next.Value); string schoolTypeXmlPath = string.Format(SCHOOL_TYPE_XML_PATH, path); return stateInfoXmlDocument.SelectNodes(schoolTypeXmlPath).Cast<XmlNode>().Distinct(); } +4