我在.net 3.5中运行了这段代码
public const string SvgNamespace = "http://www.w3.org/2000/svg";
public const string XLinkPrefix = "xlink";
public const string XLinkNamespace = "http://www.w3.org/1999/xlink";
public const string XmlNamespace = "http://www.w3.org/XML/1998/namespace";
public static readonly List<KeyValuePair<string, string>> Namespaces = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("", SvgNamespace),
new KeyValuePair<string, string>(XLinkPrefix, XLinkNamespace),
new KeyValuePair<string, string>("xml", XmlNamespace)
};
private bool _inAttrDictionary;
private string _name;
private string _namespace;
public string NamespaceAndName
{
get
{
if (_namespace == SvgNamespace)
return _name;
return Namespaces.First(x => x.Value == _namespace).Key + ":" + _name;
}
}
我目前正在将其转换为.net 2.0(删除System.Linq)。如何在代码中找到here的Enumerable.First方法(IEnumerable,Func)的功能维护?
完整资料file
最佳答案
您可能可以使用foreach
循环,例如
foreach(var item in Namespaces)
{
if(item.Value == _namespace)
return item.Key + ":" + _name;
}
关于c# - Enumerable.First(System.Linq)C#的替代方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38931361/