bfl*_*mi3 5 c# linq concatenation
鉴于IEnumerable<KeyValuePair<string,string>>,我正在尝试使用linq将值连接成一个字符串.
我的尝试:
string path = attributes.Aggregate((current, next) => "@" + current.Key + "=" + current.Value + " and @" + next.Key + "=" + next.Value);
Run Code Online (Sandbox Code Playgroud)
这会产生错误:
无法将表达式'
string' 转换为返回类型'KeyValuePair<string,string>'
在linq中有更有效的方法吗?
完整的方法......
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();
}
Run Code Online (Sandbox Code Playgroud)
Tho*_*que 15
这是你在找什么?
var strings = attributes.Select(kvp => string.Format("@{0}={1}", kvp.Key, kvp.Value));
string path = string.Join(" and ", strings);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4097 次 |
| 最近记录: |