473,503 Members | 5,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add Reference (SolutionExplorer/Using keyword)

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 the source code

For example, System.Windows.Forms is both in the SolutionExplorer and in
the using statement, some other namespaces are only inside the code.

Are these 2 differents things ?
Is there anything to do with intelissense ?

Regards,
Cybertof.
Nov 15 '05 #1
4 1882
Cybertof,

You can not add a reference to a namespace. When you select "Add
Reference", you are actually adding a reference to an assembly, which can
contain types in multiple namespaces.

When you use the "using" statement, you are saying that for that scope
(typically file), you do not have to fully quantify the names of types,
allowing you to say:

// Create a new button.
Button pobjButton = new Button();

Instead of having to do:

// Create a new button.
System.Windows.Forms.Button pobjButton = new System.Windows.Forms.Button();

It just so happens that some assembly names coincide with the namespace
names that some of the contained types are members of.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Cybertof" <cy****************@gmx.net> wrote in message
news:MP************************@msnews.microsoft.c om...
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 the source code

For example, System.Windows.Forms is both in the SolutionExplorer and in
the using statement, some other namespaces are only inside the code.

Are these 2 differents things ?
Is there anything to do with intelissense ?

Regards,
Cybertof.

Nov 15 '05 #2
Cybertof <cy****************@gmx.net> wrote in
news:MP************************@msnews.microsoft.c om:
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 the source code

For example, System.Windows.Forms is both in the SolutionExplorer and
in the using statement, some other namespaces are only inside the
code.


They are indeed two different things.

First, when you 'Add Reference...' you aren't really doing anything with
namespaces, per se. You are adding a reference to a DLL which contains
one or more namespaces, each containing one or more objects (classes,
enums, structs, etc...)

In order to make things easier on you and the IDE, the IDE/compiler
wants to know what namespaces it should search in when you type
something like

Form x = new Form()

Form is actually in the System.Windows.Forms namespace, inside the
System.Windows.Forms.DLL file (the fact that they are named the same is
for convenience - there are other namespaces available in this same
DLL). If you didn't have the line "using System.Windows.Forms" at the
top of your file, you would have to explicitly say

System.Windows.Forms.Form x = new System.Windows.Forms.Form()

If you are curious and want to see what namespaces are in any particular
'Add Reference...' item, open the 'References' group in the Solution
Explorer and double click one of them (or right-click and select 'View
in Object Browser'). Anything with a pair of braces ("{}") is a
namespace that you can reference with a "using..." line.

-mbray
Nov 15 '05 #3
In article <O7**************@TK2MSFTNGP10.phx.gbl>,
ni**************@exisconsulting.com says...
You can not add a reference to a namespace. When you select "Add
Reference", you are actually adding a reference to an assembly, which can
contain types in multiple namespaces.
When you use the "using" statement, you are saying that for that scope
(typically file), you do not have to fully quantify the names of types,
allowing you to say:

So if I understand, I cannot use a namespace with the 'using' keyword if
the assembly containing this namespace has not been added to the
Solution with 'Add Reference' ?

Am I right ?

Regards,
Cybertof.
Nov 15 '05 #4
Cybertof,

Absolutely. You need to set the assembly reference first, then you can
declare the shorthand (using "using") in your files to access the types.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Cybertof" <cy****************@gmx.net> wrote in message
news:MP************************@msnews.microsoft.c om...
In article <O7**************@TK2MSFTNGP10.phx.gbl>,
ni**************@exisconsulting.com says...
You can not add a reference to a namespace. When you select "Add
Reference", you are actually adding a reference to an assembly, which can contain types in multiple namespaces.
When you use the "using" statement, you are saying that for that scope (typically file), you do not have to fully quantify the names of types,
allowing you to say:

So if I understand, I cannot use a namespace with the 'using' keyword if
the assembly containing this namespace has not been added to the
Solution with 'Add Reference' ?

Am I right ?

Regards,
Cybertof.

Nov 15 '05 #5

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

Similar topics

13
17903
by: Abe Frohnman | last post by:
Hello all, I'm passing a reference to a class into the constructor of a form, like so: public MyForm(int count, ref Area myArea) {...} How can I use myArea outside the constructor? Should I...
4
1324
by: Philipp Sumi | last post by:
Hello all I have a thread that performs some simple I/O within a loop that runs on a separate thread. I used the using keyword to ensure the writer's disposal: using (writer) { while...
8
2106
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects,...
13
2748
by: Maxim | last post by:
Hi! A have a string variable (which is a reference type). Now I define my Method like that: void MakeFullName(string sNamePrivate) { sNamePrivate+="Gates" }
3
1704
by: Ann Huxtable | last post by:
I wrote a method that accepted a form. The signature was as ff: void foo(ref Form frm) ; I had to remove the ref keyword to get it to compile. Any idea why? I though forms would be passed by...
12
2662
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
5
7801
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The thing that troubles me about pass-by-reference into...
13
3000
by: Francois Appert | last post by:
This post was originally in the C# Corner site, but their server is down. I'd like to see if this group can answer. I program in C++ and am learning C#. The issue is: why should anybody...
12
2994
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
0
7264
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,...
0
7316
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...
1
6975
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...
0
7449
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...
1
4992
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...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
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...
0
1495
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 ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.