Concatenating IEnumerable<KeyValuePair<string,string>> values into string using Linq
c#, concatenation, linq
Solution
Is this what you're looking for?
var strings = attributes.Select(kvp => string.Format("@{0}={1}", kvp.Key, kvp.Value));
string path = string.Join(" and ", strings);
Problem
Given `IEnumerable<KeyValuePair<string,string>>`, I'm trying to use linq to concatenate the values into one string. My Attempt: ``` string path = attributes.Aggregate((current, next) => "@" + current.Key + "=" + current.Value + " and @" + next.Key + "=" + next.Value); ``` This produces the error: Cannot convert expression type '`string`' to return type '`KeyValuePair<string,string>`' Is there a more effiecient way to do this in linq? The 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(); } ```