views:

55

answers:

3

seWhen i creating a new class file i got these namespaces by default,

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

But i dont use linq,Html controls,Webcontrols,Configuration,security...

  • Why are they included by default?
  • What will happen if i exclude these from my class file?
  • What will happen if i include these without using them?
+1  A: 

These namespaces are included by default in files that you add to an ASP.Net project.

The using statement simply tells the compiler which namespaces the classes you're using are in.
If you aren't using any classes from those namespaces, the using statement will no effect whatsoever; removing them or keeping them will not matter.

Caveat: If there are two classes with the same name in two different namespaces (eg, System.Windows.Forms.Control and System.Web.UI.Control), and you having using statements for both namespaces, you won't be able to use the class unless you fully qualify it with the namespace name. (Because the compiler cannot know which one you want)

SLaks
+1  A: 

Nothing will happen if you exclude them.

Nothing will really happen if you include them.

It's recommended to remove the ones you don't need.

Not sure about the Web stuff, but Linq is included by default for all 3.5 applications, probably because it's assumed that you'll use them as much as you do system.

taylonr
+1. The linq items are included by default in 3.5. Depending on your studio version you can right click in the usings section and select "Organize usings > Remove and Sort" which will get rid of all the ones you aren't actually using in the page.
Chris Lively
+2  A: 

Why are they included by default?

Visual Studio adds a list of common includes to any class file that you create. Since it is an ASP.Net project, this is the list of using statement added to your file. For WinForms projects, it is a different set of usings.

What will happen if i exclude these from my class file?

If you don't use any classes within these namespaces within your file, excluding them will have no effect. If you use a class within those namespaces, you will have a compile error.

What will happen if i include them without using them?

Maybe it will take a few milliseconds longer to compile that file but I'm not even sure.

Marcel Gosselin
@Marcel i was mainly looking for an answer for my third question...
Pandiya Chendur