Monday, March 3, 2008

Alias a namespace/library in C# with Using;

Just a quick tip on how to make your code a little shorter... and yes this is my first C# post :)

Have a look at the using directive help on the MS site here.

This allows you to turn this:
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();

into this:
using myData=System.Data.SqlClient;

myData.SqlConnection = new myData.SqlConnection();

This is much moreuseful when you have to work with smo in Microsoft.Server.Management.Smo!!!!

No comments: