473,672 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using inside or outside my namespace

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.Collecti ons;
....

But in all the tutorial i have seen they start with using and then
start their namespace.

What would be the difference and/or advantage?

Joeri
Nov 13 '05 #1
3 7635
Joeri,

The using directive can be used in a namespace scope, in which case it
is applicable to the namespace in that file. If it is outside of the
namespace, then it is applicable to the whole file.

For more information, check out section 9.3 of the C# Language
Specification, titled "Using Directives", located at (watch for line wrap):

http://msdn.microsoft.com/library/de...rpspec_9_3.asp

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Digital Fart" <pr*********@an gelfire.com> wrote in message
news:32******** *************** *********@4ax.c om...
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.Collecti ons;
...

But in all the tutorial i have seen they start with using and then
start their namespace.

What would be the difference and/or advantage?

Joeri

Nov 13 '05 #2
(Line wrap alert - didn't fix them)
//*************** *************** *********
using System.Text;

namespace ConsoleApp
{
using System.IO;

class Class1
{
[STAThread]
static void Main(string[] args)
{
string strPath =
Directory.GetPa rent("C:\\Docum ents and Settings\\A
User").FullName ;
StringBuilder strBuilder = new
StringBuilder(s trPath);
strBuilder.Appe nd("\\test.xml" );
System.Xml.XmlD ocument objXml =
new System.Xml.XmlD ocument();
objXml.Load(str Path);
}
}
}

namespace ConsoleApp.Test
{
using System.Xml;

public class Class2
{
public Class2()
{
string strPath =
System.IO.Direc tory.GetParent( "C:\\Docume nts and
Settings\\A User").FullName ;
StringBuilder strBuilder = new
StringBuilder(s trPath);
strBuilder.Appe nd("\\test.xml" );
XmlDocument objXml = new
XmlDocument();
objXml.Load(str Path);
}
}
}

//*************** *************** *************** ******
-----Original Message-----
I was looking at the GFAX - Gnome fax application and i seethat in the main.cs the author puts the using inside his namespace.
namespace gfax {
using System;
using System.IO;
using System.Collecti ons;
....

But in all the tutorial i have seen they start with using and thenstart their namespace.

What would be the difference and/or advantage?

Joeri
.

Nov 13 '05 #3
In addition to what everybody else has pointed out, it also affects name
lookup. When the using clauses are inside the namespace, they will be
searched before the outer namespace is searched. When the using clauses are
outside the namespace, they will be searched after.

Example:
// file1.cs
namespace N1 {
namespace N2 {
class C1 { ... }
}
}
class C1 { ... }

// file2.cs
using N1.N2;
namespace N1 {
// Any code here that references C1 in here will get the outer C1
}

// file2.cs
namespace N1 {
using N1.N2;
// Any code here that references C1 in here will get N1.N2.C1
}

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.
"Digital Fart" <pr*********@an gelfire.com> wrote in message
news:32******** *************** *********@4ax.c om...
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.Collecti ons;
...

But in all the tutorial i have seen they start with using and then
start their namespace.

What would be the difference and/or advantage?

Joeri

Nov 13 '05 #4

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

Similar topics

1
1953
by: qazmlp | last post by:
One of the implementation file(.C) file has the following code namespace Utils { // declaration & definition of some functions } Is this way having named namespace( inside a .C file instead of a .h) recommended for any case ?
3
1873
by: Imre | last post by:
As far as I know, the using directive is transitive, and I'm not sure I like this. So I'd like to ask if there's any workaround. Consider this: namespace MyNameSpace { void F(SomeNameSpace::SomeOtherNameSpace::YetAnotherNameSpace::SomeType a); void G(SomeNameSpace::SomeOtherNameSpace::YetAnotherNameSpaceSomeOtherType a);
3
1910
by: Pranav Shah | last post by:
What is the differrence between using the "using" caluse outside of the namespace definition and inside the namespace. Example Outside: using System; namespace Example.Outside { }
3
1469
by: Brian Gideon | last post by:
I stumbled across something odd today about the placement of the using keyword. Section 9.3.2 of the C# v1.1 specification did not answer my question. My confusion is isolated to what happens in File1.cs of the following code. Notice that when the using keyword is placed outside of the namespace decleration its behavior is different than placing it inside the namespace decleration. Questions: 1) Section 9.3.2 of the specification...
3
2156
by: Mike L | last post by:
Should the command call "using" be before or after my namespace? **AFTER** namespace DataGridBrowser { using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Collections;
12
2839
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;
2
1509
by: Daz | last post by:
Hi everyone. Sorry for the confusing subject, I couldn't think how best to word it. What I would like to know, is if there is an equivilant to this code, in using JSON. <script type="text/javascript"> function makeTable(number_of_rows) { var table = document.createElement('table'); table.border = 1;
1
3196
by: =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki | last post by:
We have here class of C++ language: namespace Apt { class Name1 { public: class Name2; }; } I 'm give ebove class Name2 so a declalation of class without a definition
65
3897
by: Arjen | last post by:
Hi, Form a performance perspective, is it wise to use the ref statement as much as possible? Thanks! Arjen
0
8945
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
8844
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
8642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8696
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7472
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6254
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
4239
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
4439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2836
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

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.