using directive or assembly reference

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

    Expert Comment

    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

    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

    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.

    LVL 7

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now