473,218 Members | 1,310 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,218 software developers and data experts.

using / Add a reference then using

I am trying to understand what is happening when

1. I simply write

using System.Globalisation

2. I add a reference to a dll then write

using xxxxxx

Can someone put the explanation in some words, please?
Jun 27 '08 #1
4 1159
AA2e72E wrote:
I am trying to understand what is happening when

1. I simply write

using System.Globalisation

2. I add a reference to a dll then write

using xxxxxx

Can someone put the explanation in some words, please?

First you add the DLL (assembly in .NET jargon). This is essential.
This makes the contents of the assembly available to you code and it is
also linked in to Visual Studio's Intellisense etc.

Second, you can optionally put a 'using statement' in your code (top of
file or top of namespace). A 'using statement' only activates a shortcut
mechanism, it has no 'real' semantics.

Example:

using System;
... Console.WriteLine(); // Console is abbreviated

or

... System.Console.WriteLine(); // System.Console is the Full name

We normally use a 'using' but sometimes it's more convenient and/or more
clear to use the long (full) names. For example when another namespace
also has a Console class.
-HH-


Jun 27 '08 #2
On Fri, 23 May 2008 10:00:08 -0700, AA2e72E
<AA*****@discussions.microsoft.comwrote:
I am trying to understand what is happening when

1. I simply write

using System.Globalisation

2. I add a reference to a dll then write

using xxxxxx

Can someone put the explanation in some words, please?
In either case, "using" does the same thing. It allows members of the
given namespace to be used without qualification.

For every class not implemented in your own assembly, you also need to add
a reference to the assembly where that class is implemented. The members
of the System.Globalization namespace (AFAIK, you're not allowed to spell
it the British way) are, AFAIK, all implemented in the core "mscorlib.dll"
assembly, which your project will have already referenced by default in
most cases, so you can just add the namespace directive without adding a
new reference to the project.

But for some other DLL, especially one not already known to the IDE as
required for the specific project template you started with, you have to
add the reference explicitly.

Pete
Jun 27 '08 #3
On May 23, 1:00*pm, AA2e72E <AA2e...@discussions.microsoft.comwrote:
I am trying to understand what is happening when

1. I simply write

using System.Globalisation

2. I add a reference to a dll then write

using xxxxxx

Can someone put the explanation in some words, please?
Hi,

It's the same, you can create a namespace like that if you want.
if you name your dll MyCompany.MyNamespace you will end with the same
thing.
Jun 27 '08 #4
On May 23, 2:02 pm, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac...@gmail.comwrote:
On May 23, 1:00 pm, AA2e72E <AA2e...@discussions.microsoft.comwrote:
I am trying to understand what is happening when
1. I simply write
using System.Globalisation
2. I add a reference to a dll then write
using xxxxxx
Can someone put the explanation in some words, please?

Hi,

It's the same, you can create a namespace like that if you want.
if you name your dll MyCompany.MyNamespace you will end with the same
thing.
Unfortunately, C# overloads the word "using" so that it has two quite
different meanings.

Writing "using System.Globalisation;" in the top of a file means that
you can abbreviate the names of classes in that namespace without
always having to prefix "System.Globalisation" to the front of the
class name. The license to abbreviate names (i.e., drop the
namespace) lasts throughout the file.

Writing the following is very different:

using System.Globalisation.Classname
{
// some code here uses the Classname object
}

The above code creates an object of type Classname for you; it lets
you use that object between the curly braces, and the runtime then
automatically "disposes" the object for you after control passes below
the braces.
Jun 27 '08 #5

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

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
7
by: sbobrows | last post by:
{Whilst I think much of this is OT for this newsgroup, I think the issue of understanding diagnostics just about gets under the door. -mod} Hi, I'm a C++ newbie trying to use the Boost regex...
2
by: Craig Nicol | last post by:
Hi everyone, I'm looking for some help migrating my code from Microsoft VC++ 6.0, which was not the most conformant compiler I have now discovered. I'm trying to move to .NET and I've made the...
11
by: Doug | last post by:
Is there any harm in passing an object into a method with the 'ref' keyword if the object is already a reference variable? If not, is there any benefit?
4
by: Cybertof | last post by:
Hello, What is the difference between : - adding a new reference to a namespace within the SolutionExplorer (right click, Add Reference...) - adding a new reference with the 'using' keyword in...
4
by: Elad Gutman | last post by:
Hello, Something is quite puzzled to me in using the 'ref' keyword, probably due to some lack of basic understanding. Whenever I wanna change the parameter passed to a function I will use the...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
29
by: shuisheng | last post by:
Dear All, The problem of choosing pointer or reference is always confusing me. Would you please give me some suggestion on it. I appreciate your kind help. For example, I'd like to convert a...
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
65
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
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.