views:

84

answers:

4

I keep coming accross code samples online for ASP.net c#, however they never seem to list which namespaces they include, for example:

using System.Data.SqlClient;
etc etc

Am I missing something obvious or should I be expected to know exactly what namespaces each code example requires?

+8  A: 

When I'm in that situation, typically I search for the class on MSDN. The documentation will tell you which namespaces contain the class.

Cryo
Or you can google for particular class.For example if you want to know more about 'DataTable'class, just google it and you will come to know that its part of Syste.Data namespace.
Shekhar
A: 

If code samples use the assemblies that a project references by default, then you can hover on the class name and click shift+F10 which will add the using statement automatically. If the class is not in any of the referenced assemblies then you are out of luck and need to know in what assembly does the class resides.

A quick google search can help, and in time you will memorize the namespaces... Of course its best if samples included the namespace and reference info, but mostly they do not.

Numenor
A: 

If you are viewing code in Visual studio, just hover mouse over class or object you want and you will get tool tip about it if assemly of that class is present or you can google for particular class.For example if you want to know more about 'DataTable'class, just google it and you will come to know that its part of Syste.Data namespace.

Shekhar
+2  A: 

If they don't include them, you can follow this list in order:

  • Find that they are in one of the namespaces listed in the "blank code file" template , or
  • In Visual Studio You can click the missing type and press shift+F10 or Ctrl+. To get the option to automatically add the using statement (if the assembly is referenced)
  • With Resharper, Select the type and hit alt+enter for Resharper to find the namespace for you, and add it to the usings (possibly even reference the assembly as well)
  • Go to MSDN and search the name.
  • Go to Google and search the name (honestly, I normally do this before hitting MSDN anyway)
  • Compain to the article author
Philip Rieck