[C#基礎]-C# namespace應用
[C#基礎]-C# namespace應用
由於今天在和一位朋友討論C# namespace應用,所以撰寫了此一範例,有興趣的(C/P)同好,歡迎來(C/P)一下哈哈 ^ ^。
Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; //using N_A;
//using N_A.N_B;
//using N_A.N_B.N_C;
namespace CS_namespace {
class Program {
static void Main(string[] args) {
N_A.A obja = new N_A.A(30);//A obja = new A(); N_A.N_B.B objb = new N_A.N_B.B(20);//B objb = new B(); N_A.N_B.N_C.C objc = new N_A.N_B.N_C.C(10);//C objc = new C(); Console.WriteLine("objc.c=" + objc.c); Console.WriteLine("objb.b=" + objb.b); Console.WriteLine("obja.a=" + obja.a); Console.ReadKey(true); }
} }
|
Codenamespace.cs
namespace N_A {
class A {
public int a; public A() {
a=0; }
public A(int d) {
a = d; }
}
namespace N_B {
class B {
public int b; public B() {
b = 0; }
public B(int d) {
b = d; }
}
namespace N_C {
class C {
public int c; public C() {
c = 0; }
public C(int d) {
c = d; }
}
}
}
}
|