官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 孟村| 建瓯市| 郧西县| 牙克石市| 东明县| 安徽省| 浏阳市| 桐城市| 大石桥市| 呼伦贝尔市| 滦平县| 屏山县| 定远县| 大庆市| 理塘县| 吉木乃县| 潢川县| 恭城| 龙口市| 香港| 孝感市| 白城市| 新郑市| 得荣县| 越西县| 承德县| 武川县| 黎平县| 辽宁省| 鄂托克旗| 文成县| 东阳市| 遵化市| 永清县| 广河县| 刚察县| 上林县| 年辖:市辖区| 嫩江县| 巴里| 皮山县|