开发者

items get imported even without importing the Namespace

Even though we don't import "System" Name-space , its possible to access various items included in "System" Name-space. like the aliases for various types (string, single, bool, decimal...), Object Class, and also functions of the Object Class. These items are visible through Intellisence. And when we import System Name-space (using System) we get access to all the types in it (Array,Enum and lot more) 开发者_开发问答and also the actual types (System.String , System.Float etc).

Can any one please tell my why is this ?


The c# type aliases {bool, byte, char, decimal, double, float, int, long, object, sbyte, short, string, uint, ulong, ushort } aren't part of the BCL System namespace, they're actually part of the C# language

It just so happens that anywhere where you use "string" as a type name, the C# compiler treats it as System.String when compiling. I believe (I may well be wrong!) that the using statements aren't actually carried through to the MSIL that the compiler produces, so every reference to the type "string" is explicitly listed as "System.String" and every reference to StringBuilder (for example, in a class that has "using System.Text;" is expanded to "System.Text.StringBuilder".


The system namespace is automatically imported:

"The CLR will include the Namespace when the ASP.NET application is compiled. Some namespaces are automatically imported into ASP.NET pages, so you don't need to use Import to make CLR include them. System, System.Collections, System.IO, System.Web, System.Web.UI, System.Web.UI.HTMLControls, and System.Web.UI.WebControls are the namespaces that will always be taken into account by the CLR. A namespace like System.Data, which you may need if you are working with databases, needs to be imported explicetely."

http://www.redacron.com/tutorials/ASPNET/namespaces.php

Here's a related question you may be interested in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜