473,564 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is a "Reference"

Hello all,
two quick questions:

One: What is the difference between adding a reference to something in my C#
project so I can use it (for example, adding a reference to
"Microsft.Direc tX" when you need to access DirectX functionality in your
program) and the "using ..." directive?

Two: I've only seen (in books) how to add references to C# projects via the
dropdown menus of the VS.Net 2003 IDE...how do I add references to my C# app
if I'm just using the (free downloadable) .NET SDK and a simple text editor?

Thanks in advance, everyone!
Nov 17 '05 #1
5 2363
Hi Lionel,

Yo must be new :P only kidding.

The using directive when used with a namespace is just a way of not
using a classes fully qualified namespace path in code. (i.e. FileInfo
instead of System.IO.FileI nfo).

A reference is a just that, a reference to a library which contains
classes you need to use Like System.Data.dll .

A single refrence can contain classes in many namespaces and conversly
a single namespace can span a number of referenced dlls

type csc /? for help on your second problem.

Hope that helps,
Jan

Nov 17 '05 #2
Lionel,

When you add a reference, it makes your assembly aware of the types in
that reference. When you use the "using" statement at the top of a code
file, it allows you to declare type names without using the full type name.
So, you could do something like:

using System.Text;

StringBuilder builder = new StringBuilder() ;

As opposed to having to do this (without the using statement):

System.Text.Str ingBuilder builder = new System.Text.Str ingBuilder();

If you are using a text editor to develop your code, then you have to
specify the references through the compiler, using the /reference option.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Lionel" <Li****@discuss ions.microsoft. com> wrote in message
news:9E******** *************** ***********@mic rosoft.com...
Hello all,
two quick questions:

One: What is the difference between adding a reference to something in my
C#
project so I can use it (for example, adding a reference to
"Microsft.Direc tX" when you need to access DirectX functionality in your
program) and the "using ..." directive?

Two: I've only seen (in books) how to add references to C# projects via
the
dropdown menus of the VS.Net 2003 IDE...how do I add references to my C#
app
if I'm just using the (free downloadable) .NET SDK and a simple text
editor?

Thanks in advance, everyone!

Nov 17 '05 #3

"Lionel" <Li****@discuss ions.microsoft. com> wrote in message
news:9E******** *************** ***********@mic rosoft.com...
Hello all,
two quick questions:

One: What is the difference between adding a reference to something in my
C#
project so I can use it (for example, adding a reference to
"Microsft.Direc tX" when you need to access DirectX functionality in your
program) and the "using ..." directive?
The using directive only includes namespaces into the current file. That is
it allows you to use the types in those namespaces without specifying the
namespace. It does not deal with assemblys, just namespaces. References to
assemblies are used to bring in libraries that contain namespaces and types.
Two: I've only seen (in books) how to add references to C# projects via
the
dropdown menus of the VS.Net 2003 IDE...how do I add references to my C#
app
if I'm just using the (free downloadable) .NET SDK and a simple text
editor?


The C# compiler(csc.ex e) takes a /reference or /r parameter

csc /r:System.Xml.dl file.cs

would reference the System.Xml assembly. There is also a csc.rsp file in
your framework isntall folder
(x:\windows\mic rosoft.NET\Fram ework\v<version >\) which contains a set of
paraemters that the compiler always reads(unless told not to), so you do not
have to specify references to any of the dll's listed there.
Nov 17 '05 #4
Lionel <Li****@discuss ions.microsoft. com> wrote:
One: What is the difference between adding a reference to something in my C#
project so I can use it (for example, adding a reference to
"Microsft.Direc tX" when you need to access DirectX functionality in your
program) and the "using ..." directive?
A reference links against another assembly. A using directive just
means you don't need to explicitly specify the namespace later on.
Assemblies and namespaces are very different, but you *tend* to end up
with classes in assembly Foo.Bar in the Foo.Bar namespace (and
Foo.Bar.Baz etc).
Two: I've only seen (in books) how to add references to C# projects via the
dropdown menus of the VS.Net 2003 IDE...how do I add references to my C# app
if I'm just using the (free downloadable) .NET SDK and a simple text editor?


When you compile, use the /r: option.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5
Hi Lionel,

Well That was popular! Wasn't it?

Lionel, I'd recommend having a look at Reflector, a tool by Lutz
Roeder. Its a great way of having a look inside an Assembly and it's
hyperlinked too for easy navigation.
Jan

Nov 17 '05 #6

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

Similar topics

1
5057
by: Jim Abbott | last post by:
Hello Been away from VB for awhile and have forgotten how to determine what reference is missing when I goto to the project References pile. Of all things to get error on is "then goto x" being flags in 1st run. Yes, I know I am missing a reference, but which one? Any clues would be helpful. Thanks
10
5063
by: msnews.microsoft.com | last post by:
Hi, How do I add a reference in VC++.NET? In VB.NET and VC#.NET, there's an option in "Project" menu called "Add Reference". This will add a .NET DLL reference to the current project. After I add a reference, I can start using the class in the DLL as follows: Imports <TheNamespace>
5
2191
by: Trevor Andrew | last post by:
Hi There I am having some difficulty referencing Web Services. I am using Visual Studio .NET 2003, with the .NET Framework 1.1, and trying to write a VB.NET Windows Application that consumes an external Web Service When I endeavour to use the "Add Web Reference" and select a URL which I know returns a WSDL file, I get prompted with the...
1
2159
by: SrDhUS | last post by:
I get the following error when I try to add a web reference using Web Reference Dialog (VS .Net 2003) Error "The proxy settings on this computer are not configured correctly for web discovery." MSDN says: "The proxy settings on this computer are not configured correctly for Web discovery.
5
10317
by: Mike Logan | last post by:
I used WSDL.exe to generate a client side web proxy for a web service, called the web service, got the results but an array returned by the web service is not in the results. However if I use "Add Web Reference" for the same service the same function works appropriately. Here is the client proxy generated from WSDL.exe ...
3
4389
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here really understand how this could be an issue. The assemblies that the system is complaining about are ones that we build here and we're not changing...
3
2042
by: s.z.s | last post by:
Hi! I hope the solution to that is not too stupid... I've got three files: <snip test_main.cc> #include"test.hh" int main(void) { A<inta1; a1.saywhat();
4
1544
by: Neelesh Bodas | last post by:
Just wondering about exact terminology used by the standard to describe a reference. More specifically, is "reference" a type? int i = 10; // type of i is int int &ri = i; // ri is declared as a "reference to int". But what is type of ri? 'int' or 'reference to int'? -Neelesh
3
4216
by: hd95 | last post by:
vb6: what reference do I need for the "format" command?
0
7665
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...
0
8106
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...
0
7950
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...
0
6255
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...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.