Reputation: 35268
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...
Upvotes: 0
Views: 255
Reputation: 4716
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.
Upvotes: 2
Reputation: 10790
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.
Upvotes: 1
Reputation: 887453
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)
Upvotes: 1