473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using Namespace

Hi,

I am interested whether there is a significant differense if I put on
top of my class using CustomNameSpace or If I call methods in my code
by CustomNameSpace.MyMethod()

I am interested because I have to use only one method from some
namespace and I do not want to make my program heavy.

Thanks

Nov 17 '05 #1
7 2660
<ww*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi,

I am interested whether there is a significant differense if I put on
top of my class using CustomNameSpace or If I call methods in my code
by CustomNameSpace.MyMethod()

I am interested because I have to use only one method from some
namespace and I do not want to make my program heavy.

Thanks


They compile to exactly the same thing. Using in that respect is pure
syntactic sugar to save you some typing. This is very diffferent from

using(Foo f = new Foo() )
{
}

btw

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Nov 17 '05 #2
No, there is no difference. Once it is compiled into IL (intermediate
language), the fully qualified name is used, so:

this:

using System.Data.SqlClient;

void SomeFunc() {
SqlCommand cmd = new SqlCommand();
}

is the same as:

void SomeFunc() {
System.Data.SqlClient.SqlCommand cmd
= new System.Data.SqlClient.SqlCommand();
}

....except that one is longer to type. A reason not to use the "using"
construction is to avoid namespace clashes. Importing System.Windows.Forms
and System.Web.Forms (?) would have lots of clashes (think TextBox).

Scott

<ww*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi,

I am interested whether there is a significant differense if I put on
top of my class using CustomNameSpace or If I call methods in my code
by CustomNameSpace.MyMethod()

I am interested because I have to use only one method from some
namespace and I do not want to make my program heavy.

Thanks

Nov 17 '05 #3
Thank you

Nov 17 '05 #4
GTi
The name spaces:
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
have the same FILETIME type.
How can I select whitch one I want to use ?
FILETIME timespamp;
Gives a error in 2.0:
error CS0104: 'FILETIME' is an ambiguous reference between
'System.Runtime.InteropServices.FILETIME' and
'System.Runtime.InteropServices.ComTypes.FILETIME'

Nov 17 '05 #5

"GTi" <tu****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
The name spaces:
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
have the same FILETIME type.
How can I select whitch one I want to use ?
FILETIME timespamp;
Gives a error in 2.0:
error CS0104: 'FILETIME' is an ambiguous reference between
'System.Runtime.InteropServices.FILETIME' and
'System.Runtime.InteropServices.ComTypes.FILETIME'


You either only import one namespace, you fully qualify it, or you create an
alias:

using InteropFILETIME = System.Runtime.InteropServices.FILETIME;

You could also use a full namespace alias:

using Interop = System.Runtime.InteropServices;

....
Interop.FILETIME filetime;

or if you are using 2.0 you can use the new namespace alias qualifier
operator(::):

Interop::FILETIME filetime;

Nov 17 '05 #6
GTi
I solved it (rare bug)

My name space name is:
namespace MyLib.System

So trying to spesify the correct type using:
System.Runtime.InteropServices.ComTypes.FILETIME timestamp
gives me an error saying that Runtime was unknown..

Renaming my namespace to:
namespace MyLib.Lib
solved the problem....

(And I was almost giving up C# for this!)

Nov 17 '05 #7

"GTi" <tu****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I solved it (rare bug)

My name space name is:
namespace MyLib.System

So trying to spesify the correct type using:
System.Runtime.InteropServices.ComTypes.FILETIME timestamp
gives me an error saying that Runtime was unknown..

Renaming my namespace to:
namespace MyLib.Lib
solved the problem....

(And I was almost giving up C# for this!)


Ahh. C# 2.0 offers a little get around for that, the global namespace alias:

global::System.Runtime.InteropServices.ComTypes.FI LETIME timestamp;

should have worked
Nov 17 '05 #8

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

Similar topics

5
by: cppaddict | last post by:
It is typical to put the line: using namespace std; at the top of a file which makes use of std library objects. To take a simple example: #include <iostream> using namespace std;
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
3
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 { }
0
by: Simon | last post by:
I need call a LoginUser API from MC++ dll, but when I try to call the I have always the same exception: "System.NullReferenceException: Object reference not set to an instance of an object. at...
3
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...
8
by: acb | last post by:
Hi, I wrote a DLL Component (using Visual Studio 2005) and managed to include it into a C# Console application. I am now trying to include this component into a Web project. I copy the DLL...
12
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;
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
3
by: Wayne Shu | last post by:
When I read the chapter of the namespace of the book C++ Primer(3e). It explain the using directive as follow: "A using directive makes the namespace member names visible as if they were declared...
2
by: lewisms | last post by:
Hello all, I am quite new to c++/. Net so please don't shoot me down for being a newbie. Any way I am trying to make a simple multithreading program that is just to learn the ideas behind it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...

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.