Sunday, February 17, 2008

Shortcut to add Namespace automatically while coding in class file - C#

While coding a class file, you might encounter situations where you come to know that namespace is missing and you need move to top of file and add a namespace by "using" keyword.

e.g. you are writing a DAL (Data Access Layer) and have to create a variable of "SqlDataReader". Suddenly you recognize that "System.Data.SqlClient" is missing (its a pain sometimes..). In this case you need to move top and type there.

Below is the shortcut for this problem. Taking above example, type SqlDataReader and press "Alt+Shift+F10" and press enter to create a namespace automatically.



Press "Alt+Shift+F10" to show Smart Tag and press enter to select first option.



You see, "System.Data.Sqlclient" got added without going and typing it...


Let me know your comments..

3 comments: