
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What are namespaces in C#?
A namespace is for providing a way to keep one set of names separate from another. A namespace definition begins with the keyword namespace followed by the namespace name as follows −
namespace namespace_name { // code declarations }
Define a Namespace −
namespace namespace_name { // code declarations }
The following is an example showing how to use namespaces in C# −
Example
using System; namespace first_space { class namespace_cl { public void func() { Console.WriteLine("Inside first_space"); } } } namespace second_space { class namespace_cl { public void func() { Console.WriteLine("Inside second_space"); } } } class TestClass { static void Main(string[] args) { first_space.namespace_cl fc = new first_space.namespace_cl(); second_space.namespace_cl sc = new second_space.namespace_cl(); fc.func(); sc.func(); Console.ReadKey(); } }
Output
Inside first_space Inside second_space
- Related Articles
- What are nested namespaces in C#?
- What are Python namespaces all about?
- What are some of the important namespaces in C#? Provide a brief description of each
- How to define namespaces in C#?
- How to use namespaces in C++?
- Can namespaces be nested in C++?
- How will you compare namespaces in Python and C++?
- Namespaces and Scoping in Python
- Namespaces and Scope in Python
- What is difference between builtin and globals namespaces in Python?
- PHP Namespaces Overview
- PHP Using namespaces
- PHP Aliasing/Importing namespaces
- PHP Declaring sub-namespaces
- PHP Defining Multiple Namespaces in same file

Advertisements