I previously suggested a better method for getting attributes for an System.Xml.XmlNode in a response to an post by Marcus. Craig Nicholson highlighted in a comment that the code i provided can be even further optimized.

private static string GetAttribute(XmlNode node, string name) {     XmlElement elm = node as XmlElement;     return (elm == null) ? string.Empty : elm.GetAttribute(name); } 

.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, “Courier New”, courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

Craig’s first improvement includes using string.Empty instead of “". When using "” a new empty string will be allocated in the memory, but the string.Empty will return a reference to an empty string. This will affect garbace collecting performance, since it will have less objects to clean up if you use string.Empty.

The second improvement Craig supplied was to use the C# conditional ?: operator, to have it on a single line. This will not affect performance since it will be expanded to an if-else statement by the compiler, but the code looks cleaner.

This is what I really like; clean looking and optimized code!