Hello, I am new to asp.net. I am confused what is the difference between "using MyNameSpace"; and "namespace MyNameSpace". My demo code is the following ...
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
using MyNameSpace ;namespace MyNameSpace
using MyNameSpace ;
namespace MyNameSpace
{ public partial class DemoPage : System.Web.UI.Page { My code here } }
In the above code, is there any difference between the two highlighted statements or not. If so, what is it?
Thanks in advance...
Yes, they provide additional services.
A using the following directive:
using MyNamespace;
MyNamespace - , MyNamespace.Foo, Foo , , .
MyNamespace
MyNamespace.Foo
Foo
: ", , ". MyNamespace.Foo, :
namespace MyNamespace { public class Foo { ... } }
? using , , - .
using
using "" . , , , . namespace :
namespace
first.cs:
first.cs
// define the namespace "SomeNamespace" namespace SomeNamespace { // define a type within the namespace class SomeClass { } }
second.cs:
second.cs
using SomeNamespace; // define the namespace "OtherNamespace" namespace OtherNamespace { class OtherClass { void SomeMethod() { // use the type "SomeClass", defined in the "SomeNamespace" namespace // note that without the using directive above we would need to write // SomeNamespace.SomeClass for this to work. SomeClass temp = new SomeClass(); } } }
temp , using.
temp
, . namespace , using , .
using , , .
As you have it using System.Web.UI, the identifier System.Web.UI.Pagecan be written as simple Pageas the compiler knows about the classes in this namespace. If you didn’t have this operator using, you would need the full name for the compiler to find out where to find the class.
using System.Web.UI
System.Web.UI.Page
Page
Source: https://habr.com/ru/post/1758678/More articles:A few description attributes on emums - .netCreate directory on boot using django - pythonAVCaptureStillImageOutput outputSettings memory leak - memoryShowing events of DOM elements and their handlers - javascriptОбъединение дубликатов записей в 1 запись с одинаковыми полями таблицы и таблицы - functionREST сервисное приложение и отдельный интерфейс - хорошая идея? - designРабота с WCF, Windows Phone 7 и ASP.Net - c#Python: date formatted in% x (locale) does not meet expectations - pythonHow to get the selected row in DataGrid in a smartphone application? - .netHashing no longer works in .Net 4.0, despite MSDN workarounds - asp.netAll Articles