[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


using directive or assembly reference

Posted on 2011-10-05
Medium Priority
Last Modified: 2013-12-16
What is an assembly reference or using directive in C#?
Question by:mike9380
  • 2

Expert Comment

by:Bill Nolan
ID: 36921817
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).
LVL 40

Accepted Solution

Jacques Bourgeois (James Burger) earned 2000 total points
ID: 36921831
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

LVL 15

Expert Comment

ID: 36923567
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.


Expert Comment

by:Bill Nolan
ID: 36932016
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.)

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month20 days, 1 hour left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question