Wednesday, June 29, 2005

Include Namespaces in Sample Code

To people providing code examples: Please, please, please include the class's namespace in your code (use fully-qualified classnames). For example, instead of x=new XmlDocument(); use x=new System.Xml.XmlDocument();

It's easy for someone to put a "using" at the top of a code block, but most people posting sample code on the internet only paste snippets of code, and without having the "using" blocks, we have no idea which namespace the objects belong to!

So, unless the class comes from the System namespace, include the fully-qualified classname in your code. It will go a long way to helping people read and understand your code snippets.

Note to self: Make sure that I use fully-qualified classnames in all of my sample code.....