using directive or assembly reference

What is an assembly reference or using directive in C#?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Navneet.Net Full Stack DeveloperCommented:
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.)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.