using directive or assembly reference

What is an assembly reference or using directive in C#?
Who is Participating?
Jacques Bourgeois (James Burger)PresidentCommented:
An assembly reference is a way to tell the Visual Studio environment that you want to use a particular assembly. Once referenced, the classes in the assembly become available in your project and are listed in aids in different tools.

You set a reference through a right click on the References entry in the Solution Explorer.


Using directives are a way to simplify your code by making it possible to specify the namespace for classes that you use often.

As an exempla, if you want to connect to SQL Server, you normally need to declare objects with the following syntax:
public class Foo
    System.Data.SqlClient.SqlConnection connection;
    System.Data.SqlClient.SqlCommand command;

Open in new window

If you add a using directive at the top of the file however, you do not need to specify the namespace:
using System.Data.SqlClient;
public class Foo
    SqlConnection connection;
    SqlCommand command;

Open in new window

Bill NolanOwner, Lead Technology ProgrammerCommented:
The "using" directive instructs the compiler of the namespaces you will be referencing.
Assembly references simply tell the compiler which assemblies (dll's, e.g.) to include during compilation/linking (where the namespaces are manifested).
NavneetSoftware EngineerCommented:
Assemble Reference :
There are n' numbr of DLL's in .Net Framework, having all those in your Solution makes no-sense.
hence we have assembly reference, By Default  Solution when drawn from Template take all the required
assemble, So Windows App might require different set of assembly and Web App the another set of Assemblies
These set of assemblies are minimum required assemblies.
Over and above that if you require any other assemble from .Net framework itself or and third pary DLL's,
You add the reference to that assembly in your solution

Using directive :
It is to allow the use of types in a namespace so that you do not have to qualify the use of a type in that namespace
and scope of a using directive is limited to the file in which it appears.

Bill NolanOwner, Lead Technology ProgrammerCommented:
JamesBurger: thanks for correcting me on the use of "using"!

(Well, I suppose my statement actually IS basically correct - but I hadn't pointed out [and had forgotten, actually] the important distinction that the mechanism is only necessary when you'd like to avoid fully qualifying the namespace at each instance.)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.