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

  • 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:

主站蜘蛛池模板: 怀化市| 青河县| 壶关县| 海城市| 阿克苏市| 卢氏县| 马鞍山市| 鄂尔多斯市| 诏安县| 静安区| 六盘水市| 开化县| 剑河县| 石柱| 招远市| 台南市| 庆云县| 莱州市| 昭通市| 原平市| 龙井市| 红原县| 秦安县| 兴海县| 武强县| 乌兰察布市| 衡山县| 临泉县| 申扎县| 无锡市| 宜君县| 绥阳县| 潜山县| 岫岩| 南开区| 通山县| 大庆市| 东乡县| 台湾省| 涿州市| 通道|