Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
How to Create and Use Alias Command in Linux
Next article icon

How to use :: Namespace Alias Qualifier in C#

Last Updated : 06 Mar, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report

Namespace Alias Qualifier(::) makes the use of alias name in place of longer namespace and it provides a way to avoid ambiguous definitions of the classes. It is always positioned between two identifiers. The qualifier looks like two colons(::) with an alias name and the class name. It can be global. Thus it doesn’t invoke a lookup in the aliased namespace but in the global namespace.

Syntax:

alias_name::class-name;

Example:




// C# program to illustrate how to use
// the :: Namespace Alias Qualifier
using System;
  
// creating aliased name
using first = firstnamespace;
using sec = secondnamespace;
  
namespace Geeks {
  
class GFG {
  
    // Main Method
    static void Main()
    {
  
        // use of Namespace alias qualifier(::)
        first::GFG1 obj1 = new first::GFG1(); 
        obj1.display();
    }
}
}
  
// Both namespaces have a 
// class named GFG1
namespace firstnamespace {
  
class GFG1 {
  
    public void display()
    {
        Console.WriteLine("It is the first namespace.");
    }
}
}
  
namespace secondnamespace {
  
class GFG1 {
  
    public void display()
    {
        Console.WriteLine("It is the second namespace.");
    }
}
}
 
 
Output:
  It is the first namespace.  

Note: The namespace alias qualifier :: is only used for the namespaces or aliases and cannot be used for subclasses.

Example:

  System.Collections::lists obj= new System.Collections.lists() // illegal  aliasname = System.Collections;  aliasname::lists obj = new aliasname::lists(); // Legal  




// C# program to illustrate how to use
// the :: Namespace Alias Qualifier
using aliasname = System.Collections;
  
namespace Geeks {
  
class GFG {
  
    // Main Method
    static void Main()
    {
        // using :: Namespace Alias Qualifier
        aliasname::Hashtable obj = new aliasname::Hashtable();
  
        // Add items to the table.
        obj.Add("ASCII value of A is:", "65");
        obj.Add("ASCII value of B is:", "66");
  
        // displaying the result
        foreach(string i in obj.Keys)
        {
            System.Console.WriteLine(i + " " + obj[i]);
        }
    }
}
}
 
 
Output:
  ASCII value of A is: 65  ASCII value of B is: 66  


Next Article
How to Create and Use Alias Command in Linux
author
ravikishor
Improve
Article Tags :
  • C#

Similar Reads

  • C# | How to use Interface References
    In C#, you are allowed to create a reference variable of an interface type or in other words, you are allowed to create an interface reference variable. Such kind of variable can refer to any object that implements its interface. An interface reference variable only knows that methods which are decl
    5 min read
  • How to Create and Use Alias Command in Linux
    Imagine you're lost in a maze of complicated Linux commands. You stumble upon a secret doorway marked "Alias," and inside you find shortcuts to all your favorite commands! That's what creating aliases is like. You get to make your own mini-commands for the long ones you use all the time, making thin
    6 min read
  • How to declare namespace in JavaScript ?
    The coding standard of assigning scope to identifiers (names of types, functions, variables, and so on) to avoid conflicts between them is known as a namespace. It is a framework for a collection of identifiers, functions, and methods. It gives its contents a sense of direction so that they are easi
    3 min read
  • Nested Inline Namespaces In C++20
    The Inline Namespace is a feature that was first introduced in C++ 11. They can also be nested inside another namespace and the members of this nested namespace can be accessed as if they are the members of the parent namespace. Their syntax may seem complex so in C++20, a new version introduced a n
    2 min read
  • How to check whether the event namespace is used in jQuery ?
    The jQuery is lightweight, and it has a lot of features like HTML/DOM manipulation, CSS manipulation, HTML event methods, effects and animations, AJAX, utilities. Many multinational companies like Google, IBM, and Microsoft use the jQuery library in their application. The event.namespace property re
    1 min read
  • How to set Name of the ComboBox in C#?
    In Windows forms, ComboBox provides two different features in a single control, it means ComboBox works as both TextBox and ListBox. In ComboBox, only one item is displayed at a time and the rest of the items are present in the drop-down menu. You are allowed to provide a name to your ComboBox by us
    3 min read
  • How to Install Nuget Package in C#?
    In this tutorial, we will be seeing how to install NuGet packages in C#. NuGet is the official package-manager for .NET. Packages are basically compiled libraries with some descriptive metadata. NuGet is an important tool for any modern development platform through which developers can create, share
    3 min read
  • How to Install a C# Class Library in Visual Studio?
    A C# library project is a separate project used to hold utility classes. So this might be the class that handles our database or might handle some communications with the network. In our case, we are going to create a math library that is a stand-in for some of those other cases. It is a single sour
    3 min read
  • How to set the Name of the Button in C#?
    A Button is an essential part of an application, or software, or webpage. It allows the user to interact with the application or software. In Button, you are allowed to set the name of your button by using Name property. You can use this property in two different methods: 1. Design-Time: It is the e
    3 min read
  • XML Namespaces in Android
    In an XML file, namespaces are used to provide elements and attributes with distinctive names. Names for elements or attributes in an XML instance may come from different XML vocabularies. The ambiguity between similar elements or attributes can be eliminated if each vocabulary is given its own name
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences