给定 IEnumerable<KeyValuePair<string,string>>
,我正在尝试使用 LINQ 将值连接成一个字符串。
我的尝试:
string path = attributes.Aggregate((current, next) => "@" + current.Key + "=" + current.Value + " and @" + next.Key + "=" + next.Value);
这会产生错误:
在linq中有更有效的方法吗?无法将表达式类型 '
string
' 转换为返回类型 'KeyValuePair<string,string>
'
完整的方法...
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();
}
string.ToArray()
进行转换。 - bflemi3IEnumerable<string>
的String.Join
重载方法,它只接受数组。 - Thomas Levesque