Home » .Net

The 'using' Keyword in C#

In this article, we are going to learn to use ‘using’ keyword in C#. What is ‘using’ keyword, how and when it is used in a C# program?
Submitted by IncludeHelp, on August 11, 2018

Prerequisite: Namespace in C#

If you want to include namespace in a program then we need to use using keyword. For example we use Console class which is defined in System namespace that’s why we need to include System namespace using using keyword.

If we want to use Console class without include then we can also access it with the help of . (dot) operator like that:

System.Console.WriteLine("Hello World");

Example:

using System;
using System.Collections;

using namespace1;
using namespace2;

namespace namespace1
{
    class ABC
    {
        public void fun()
        {
            Console.WriteLine("Inside Namespace1");
        }
    }
}

namespace namespace2
{
    class XYZ
    {
        public void fun()
        {
            Console.WriteLine("Inside Namespace2");
        }
    }
}    
    
class Program
{
    static void Main()
    {
        ABC OB1 = new ABC();
        XYZ OB2 = new XYZ();

        OB1.fun();
        OB2.fun();

    }
}

Output

    Inside Namespace1
    Inside Namespace2

Read more: Nested Namespace in C#






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.