473,779 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Placing using before namespace{} or in namespace{} - What's the difference?

Can someone tell me what is the difference in placing the using in the
namespace{} and before the namespace{} ?

namespace MyProj
{
using System;
using System.Web;
}

using System;
using System.Web;
namespace MyProj
{
}
Nov 15 '05 #1
2 1521
Hi Empire,

Comments in-line.

"Empire City" <a@b.com> wrote in message
news:Pw******** ************@tw ister.nyc.rr.co m...
Can someone tell me what is the difference in placing the using in the
namespace{} and before the namespace{} ?

namespace MyProj
{
using System;
using System.Web;
}
Here the using statements only apply to the code within the block defined by
MyProj. If you added another namespace to the same file, like this:

namespace MyOtherProj
{
class MyClass { Int32 myInt; }
}

You would get a compiler error "The type or namespace Int32 could not be
found...".
using System;
using System.Web;
namespace MyProj
{
}


On this one, the using statements apply to all code in this file. For
example, if I defined:

namespace MyOtherProj
{
}

in the same file, I wouldn't need to re-define the using statements.

I suppose if someone felt a need to define multiple namespaces in the same
file, the second format would be useful.

Joe
--
http://www.csharp-station.com
Nov 15 '05 #2
OK, thank you. Makes perfect sense now. I think what threw me off was the
Duwamish example puts the using within the namespace, while when you create
a web form the usings are above the namespace.

--

"Joe Mayo" <jm***@ddiieess ppaammeerrssddi iee.com> wrote in message
news:uF******** ******@TK2MSFTN GP10.phx.gbl...
Hi Empire,

Comments in-line.

"Empire City" <a@b.com> wrote in message
news:Pw******** ************@tw ister.nyc.rr.co m...
Can someone tell me what is the difference in placing the using in the
namespace{} and before the namespace{} ?

namespace MyProj
{
using System;
using System.Web;
}
Here the using statements only apply to the code within the block defined

by MyProj. If you added another namespace to the same file, like this:

namespace MyOtherProj
{
class MyClass { Int32 myInt; }
}

You would get a compiler error "The type or namespace Int32 could not be
found...".
using System;
using System.Web;
namespace MyProj
{
}


On this one, the using statements apply to all code in this file. For
example, if I defined:

namespace MyOtherProj
{
}

in the same file, I wouldn't need to re-define the using statements.

I suppose if someone felt a need to define multiple namespaces in the same
file, the second format would be useful.

Joe
--
http://www.csharp-station.com

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
1538
by: Leon | last post by:
Hi all. For my application I'm using a third-party library which is supplied as a library file (.lib) and an associated header file to prototype the functions defined in the library. Important is that the library is already compiled. Now, this library defines only functions, and they are declared in the global namespace. Since this is rather ugly and inconvenient, I want to place these functions in their own namespace.
3
7643
by: Digital Fart | last post by:
I was looking at the GFAX - Gnome fax application and i see that in the main.cs the author puts the using inside his namespace. namespace gfax { using System; using System.IO; using System.Collections; .... But in all the tutorial i have seen they start with using and then
25
2675
by: JeffS | last post by:
Honest, I scoured the comp.lang.c.faq for this but found nothing. :) Is there a library function for placing the cursor position in the console? Or is it something that can only be done with a platform API call? I was able to do this in Windows with a Windows.h function, but I want to also do it on Linux/Unix as well. I won't ask for a Linux API call that positions the cursor, as that is
2
1059
by: Frank Dietrich | last post by:
Hi, I am wondering if it makes a difference whether I add a using <NameSpace>; statement to the "using section" or leave it out and later in code reference the complete Namespace like public class ...
2
2817
by: Dickyb | last post by:
Extracting an Icon and Placing It On The Desktop (C# Language) I constructed a suite of programs in C++ several years ago that handle my financial portfolio, and now I have converted them to C#. The only significant problem that I have encountered in the conversion is this one - extracting an icon from the 'KTEntryPoint' program into the software suite and placing that icon on the PC Desktop.
6
991
by: Just Me | last post by:
Sometime when I place my usercontrol on a form I get a message that it can't find a file that is referenced. The file is the only C# file in the solution (say Library.DLL) . I just noticed that the C# bin folder has a Debug and Release Folders which contain Library.DLL, while vb bin contains Library.DLL. Also, the file in question is the first file in the build sequence. Also, that library shares a namespace with a VB library which...
3
4495
by: pyramus | last post by:
I am wondering which one should be preferred for creating a local synonym within a function definition. Let's say I have a type in my library called MyLib::Foundation::int32, which I can't stand typing all the time. Should I do: void foo() { typedef MyLib::Foundation::int32 int32; int32 x = 0; }
12
2861
by: Keith Patrick | last post by:
Can someone tell me the difference in terms of actual implications using: namespace MyNamespace { using System; class MyClass {...} } vs. using System;
6
9016
by: Halcyon | last post by:
so i've been "using namespace std" happily in all my source files at the global scope, and i then go to to use cout, vector, string etc without having to use std:: everytime. However today i was informed that i should eschew "using namespace std" and use "using std::string", "std::vector" et al. I don't quite get what the potential drawbacks of "using namespace std" are... i perused a few books, but most authors *do* use "using...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.