- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to define namespaces in C#?
A namespace is designed 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 }
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
- How to use namespaces in C++?
- What are namespaces in C#?
- How will you compare namespaces in Python and C++?
- Can namespaces be nested in C++?
- What are nested namespaces in C#?
- How to generate XML documents with namespaces in Python?
- How to define constants in C++?
- How to define methods in C#?
- How to define variables in C#?
- How to define a variable in C++?
- How to define an array in C#?
- How to define character constants in C#?
- How to define a structure in C#
- How to define custom methods in C#?
- How to define jagged arrays in C#?

Advertisements