473,406 Members | 2,698 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,406 software developers and data experts.

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.DirectX" 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 2350
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.FileInfo).

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.StringBuilder builder = new System.Text.StringBuilder();

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.com

"Lionel" <Li****@discussions.microsoft.com> wrote in message
news:9E**********************************@microsof t.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.DirectX" 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****@discussions.microsoft.com> wrote in message
news:9E**********************************@microsof t.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.DirectX" 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.exe) 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\microsoft.NET\Framework\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****@discussions.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.DirectX" 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.com>
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
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...
10
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...
5
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...
1
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."...
5
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...
3
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...
3
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
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...
3
by: hd95 | last post by:
vb6: what reference do I need for the "format" command?
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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,...
0
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...

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.