XmlNode attribute
=
node.Attributes.GetNamedItem(
"
myAttribute
"
);
为什么不直接用
XmlAttribute attribute
=
node.Attributes[
"
myAttribute
"
];
于是就check了一下,发现
XmlAttributeCollection的Indexer实际上是call GetNamedItem方法,然后做了一个转换:
public
virtual
XmlAttribute
this
[
string
name]
{
get
{
return (XmlAttribute) this.GetNamedItem(name);
}
}
{
get
{
return (XmlAttribute) this.GetNamedItem(name);
}
}
而直接call GetNamedItem方法,就可以少转换一次。这样在循环处理xml文档的时候,可以 一定程度的提高效率. :)