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

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

主站蜘蛛池模板: 阜平县| 渭源县| 西林县| 名山县| 九台市| 报价| 黄龙县| 葵青区| 九龙城区| 兖州市| 渭源县| 文登市| 大同县| 北票市| 微山县| 浦城县| 湖北省| 鄱阳县| 凤阳县| 灌南县| 龙门县| 滕州市| 中超| 宁德市| 麻阳| 汶上县| 甘谷县| 富阳市| 兴城市| 华安县| 巴青县| 紫金县| 西和县| 花莲市| 鄢陵县| 兴和县| 安康市| 历史| 连云港市| 喜德县| 溆浦县|