- Learn C# in 7 days
- Gaurav Aroraa
- 179字
- 2021-07-08 09:51:22
3 (Day02)
This is the namespace of our existing console application.
A namespace is a way to keep one set of names separate from another, which means you can create as many namespaces as you want and the classes under different namespaces will treat them as a separate, although they have the same name; that is, if you declare a ClassExample class in namespace Day02, it would be different from the ClassExample class declared in the Day02New namespace and will work without any conflicts.
This is a typical example that shows two classes of the same name with two different namespaces:
namespace Day02 { public class ClassExample { public void Display() { Console.WriteLine("This is a class 'ClassExample' of namespace 'Day02'. "); } } } namespace Day02New { public class ClassExample { public void Display() { Console.WriteLine("This is a class 'ClassExample' of namespace 'Day02New'. "); } } }
The preceding code would be called like this:
private static void SameClassDifferentNamespacesExample() { var class1 = new ClassExample(); var class2 = new Day02New.ClassExample(); class1.Display(); class2.Display(); }
This will return the following output:

推薦閱讀
- R語言數(shù)據(jù)分析從入門到精通
- Mastering Zabbix(Second Edition)
- 計算機(jī)圖形學(xué)編程(使用OpenGL和C++)(第2版)
- Java編程指南:基礎(chǔ)知識、類庫應(yīng)用及案例設(shè)計
- Django Design Patterns and Best Practices
- Spring Cloud、Nginx高并發(fā)核心編程
- R Deep Learning Cookbook
- UML 基礎(chǔ)與 Rose 建模案例(第3版)
- Android程序設(shè)計基礎(chǔ)
- C++面向?qū)ο蟪绦蛟O(shè)計習(xí)題解答與上機(jī)指導(dǎo)(第三版)
- Java程序設(shè)計入門
- 軟件供應(yīng)鏈安全:源代碼缺陷實例剖析
- Java Web應(yīng)用開發(fā)給力起飛
- PHP+MySQL Web應(yīng)用開發(fā)教程
- VMware vSphere Design Essentials