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

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

主站蜘蛛池模板: 长海县| 深泽县| 荔浦县| 化州市| 本溪| 汕尾市| 兖州市| 安新县| 梓潼县| 宝山区| 台安县| 阳信县| 合山市| 综艺| 扶沟县| 新和县| 内乡县| 肥乡县| 偏关县| 巴林右旗| 仁怀市| 永宁县| 介休市| 炎陵县| 黔西县| 九寨沟县| 贺兰县| 白银市| 台中市| 五峰| 镇巴县| 昭觉县| 天等县| 涟水县| 旬阳县| 泸定县| 上犹县| 庐江县| 承德市| 龙里县| 嘉荫县|