目錄
?c#程序結(jié)構(gòu)簡(jiǎn)述
1 類(lèi)和對(duì)象
2 類(lèi)型參數(shù)
3 基類(lèi)
4 結(jié)構(gòu)
5 接口
6 枚舉
7 可為 null 的類(lèi)型
8 元組
9 成員
10 輔助功能
?c#程序結(jié)構(gòu)簡(jiǎn)述
C# 中的關(guān)鍵組織結(jié)構(gòu)概念包括程序、命名空間、類(lèi)型、成員和程序集。 程序聲明類(lèi)型,而類(lèi)型則包含成員,并被整理到命名空間中。 類(lèi)型示例包括類(lèi)、結(jié)構(gòu)和接口。 成員示例包括字段、方法、屬性和事件。 編譯完的 C# 程序?qū)嶋H上會(huì)打包到程序集中。 程序集的文件擴(kuò)展名通常為?.exe?或?.dll,具體視其分別實(shí)現(xiàn)的是應(yīng)用程序還是庫(kù)而定。
1 類(lèi)和對(duì)象
?//demo類(lèi)申明,包含兩個(gè)屬性,構(gòu)造方法
????class?demo
????{
????????public?int?X { get; }
????????public?int?Y { get; }
????????public?demo(int?x, int?y) => (X, Y) = (x, y);
????????public?void?sum()
????????{
????????????Console.WriteLine(X + Y);
????????}
???????
}
創(chuàng)建對(duì)象并使用類(lèi):
demo d=new?demo(12,12);
????????????d.sum();
2 類(lèi)型參數(shù)
?//類(lèi)型參數(shù): T1 T2和預(yù)定義的類(lèi)型參數(shù)
????class?TClass<T1,T2>
????{
????????public?T1 X { get; }
????????public?T2 Y { get; }
????????public?TClass(T1 x, T2 y) => (X, Y) = (x, y);
????????public?void?print()
????????{
????????????Console.WriteLine(typeof(T1));
????????????Console.WriteLine(typeof(T2));
????????????Console.WriteLine("x={0},y={1}",X,Y);
????????}
}
使用類(lèi):
?TClass<int, double> tc = new?TClass<int, double>(12, 14.5);
????????????//var tc2 = new TClass<int, double>(12, 14.5); ?//使用關(guān)鍵字var省去類(lèi)型的寫(xiě)法
????????????tc.print();
????????????//獲取屬性
????????????int?x = tc.X;
????????????double?y = tc.Y;
????????????Console.WriteLine(x * y);
3 基類(lèi)
???
?//類(lèi)聲明可以指定基類(lèi)。 在類(lèi)名和類(lèi)型參數(shù)后面加上冒號(hào)和基類(lèi)的名稱(chēng)。
????public?class?point3D:demo
????{
????????public?int?Z { get; set; }
????????//使用base調(diào)用父類(lèi)構(gòu)造方法初始化成員x,y
????????public?point3D(int?x,int?y,int?z) : base(x, y)
????????{
????????????Z = z;
????????}
????????public?void?print()
????????{
????????????Console.WriteLine("x={0},y={1},z={2}", X, Y, Z);
????????}
}
使用:
?//可以將類(lèi)類(lèi)型隱式轉(zhuǎn)換成其任意基類(lèi)類(lèi)型
????????????demo a = new?demo(12,23);
????????????demo b = new?point3D(12, 34, 33);
????????????point3D s = new?point3D(1, 2, 3);
????????????s.print();
4 結(jié)構(gòu)
???
?class?myStruct
????{
????????/*
????結(jié)構(gòu)類(lèi)型是較為簡(jiǎn)單的類(lèi)型,其主要目的是存儲(chǔ)數(shù)據(jù)值。 結(jié)構(gòu)不能聲明基類(lèi)型;
???它們從 System.ValueType 隱式派生。 不能從 struct 類(lèi)型派生其他 struct 類(lèi)型。 這些類(lèi)型已隱式密封。
????*/
????????public?struct?sp
????????{
????????????public?int?X { get; set; }
????????????public?int?Y { get; set; }
????????????public??sp(int?x, int?y) => (X, Y) = (x, y);
???????????
????????????public?void?print()
????????????{
????????????????Console.WriteLine("結(jié)構(gòu)體方法,x*y={0}", X * Y);
????????????}
????????????????
????????????
????????}
???????
????}
使用結(jié)構(gòu):
?
myStruct.sp s=new?myStruct.sp();
????????????s.X = 22;
????????????s.Y = 33;
????????????s.print();
5 接口
接口定義了可由類(lèi)和結(jié)構(gòu)實(shí)現(xiàn)的協(xié)定。 定義接口來(lái)聲明在不同類(lèi)型之間共享的功能。接口可以包含方法、屬性、事件和索引器。 接口通常不提供所定義成員的實(shí)現(xiàn),僅指定必須由實(shí)現(xiàn)接口的類(lèi)或結(jié)構(gòu)提供的成員。
接口可以“多重繼承”?。
??
//定義接口
????interface?myIF
????{
????????void?myIF1();
????}
????interface?text
????{
????????void?text1();
????}
????//接口之間也可以繼承,并且支持多繼承
????interface?myIFandtext: myIF, text
????{
????????void?all();
????}
????//類(lèi)和結(jié)構(gòu)可以實(shí)現(xiàn)多個(gè)接口
????public?class?test?: myIF, text
????{
????????public?void?myIF1()
????????{
????????????Console.WriteLine("myIF");
????????}
????????public?void?text1()
????????{
????????????Console.WriteLine("text1");
????????}
????}
????public?struct?ms: myIF, text
????{
????????public?void?myIF1()
????????{
????????????Console.WriteLine("myIF");
????????}
????????public?void?text1()
????????{
????????????Console.WriteLine("text1");
????????}
}
?public?class?tf?: myIFandtext
????{
????????public?void?all()
????????{
????????????throw?new?NotImplementedException();
????????}
????????public?void?myIF1()
????????{
????????????throw?new?NotImplementedException();
????????}
????????public?void?text1()
????????{
????????????throw?new?NotImplementedException();
????????}
????}
使用:
?
?test t = new?test();
????????????t.myIF1();
????????????t.text1();
????????????ms m = new?ms();
????????????m.text1();
????????????m.myIF1();
?//當(dāng)類(lèi)或結(jié)構(gòu)實(shí)現(xiàn)特定接口時(shí),此類(lèi)或結(jié)構(gòu)的實(shí)例可以隱式轉(zhuǎn)換成相應(yīng)的接口類(lèi)型。
????????????myIFandtext ft = new?tf();
????????????ft.all();
6 枚舉
枚舉類(lèi)型定義了一組常數(shù)值。
?//定義枚舉
????public?enum?Seasons
????{
????????None = 0,
????????Summer = 1,
????????Autumn = 2,
????????Winter = 4,
????????Spring = 8,
????????All = Summer | Autumn | Winter | Spring
????}
????class?Program
????{
????????static?void?Main(string[] args)
????????{
????????????//使用枚舉
????????????Console.WriteLine(Seasons.None);
????????????Console.WriteLine(Seasons.Summer);
????????????Console.WriteLine(Seasons.Autumn);
????????????Console.WriteLine(Seasons.Winter);
????????????Console.WriteLine(Seasons.Spring);
????????????Console.WriteLine(Seasons.All);
????????????var?s = Seasons.Spring;
????????????Console.WriteLine(s);
????????????Console.ReadLine();
????????}
????}
7 可為 null 的類(lèi)型
任何類(lèi)型的變量都可以聲明為“不可為 null”或“可為 null”_。
??
static?void?Main(string[] args)
????????{
????????????int? a = default;
????????????a = 7;
????????????string?name = default;
????????????name = "zhangsan";
????????????Console.WriteLine("name={0},a={1}", name, a);
????????????Console.ReadLine();
????????}
8 元組
C# 支持元組,后者提供了簡(jiǎn)潔的語(yǔ)法來(lái)將多個(gè)數(shù)據(jù)元素分組成一個(gè)輕型數(shù)據(jù)結(jié)構(gòu)。 通過(guò)聲明?(?和?)?之間的成員的類(lèi)型和名稱(chēng)來(lái)實(shí)例化元組,
static?void?Main(string[] args)
????????{
????????????//元組為具有多個(gè)成員的數(shù)據(jù)結(jié)構(gòu)提供了一種替代方法
????????????(int?a, int?b) ab = (22, 33);
????????????Console.WriteLine("a+b={0}", ab.a + ab.b);
????????????Console.ReadLine();
????????}
9 成員
class?的成員要么是靜態(tài)成員,要么是實(shí)例成員。 靜態(tài)成員屬于類(lèi),而實(shí)例成員則屬于對(duì)象(類(lèi)實(shí)例)。
以下列表概述了類(lèi)可以包含的成員類(lèi)型。
- 常量:與類(lèi)相關(guān)聯(lián)的常量值
- 字段:與類(lèi)關(guān)聯(lián)的變量
- 方法:類(lèi)可執(zhí)行的操作
- 屬性:與讀取和寫(xiě)入類(lèi)的已命名屬性相關(guān)聯(lián)的操作
- 索引器:與將類(lèi)實(shí)例編入索引(像處理數(shù)組一樣)相關(guān)聯(lián)的操作
- 事件:類(lèi)可以生成的通知
- 運(yùn)算符:類(lèi)支持的轉(zhuǎn)換和表達(dá)式運(yùn)算符
- 構(gòu)造函數(shù):初始化類(lèi)實(shí)例或類(lèi)本身所需的操作
- 終結(jié)器:永久放棄類(lèi)的實(shí)例之前完成的操作
- 類(lèi)型:類(lèi)聲明的嵌套類(lèi)型
10 輔助功能
每個(gè)類(lèi)成員都有關(guān)聯(lián)的可訪(fǎng)問(wèn)性,用于控制能夠訪(fǎng)問(wèn)成員的程序文本區(qū)域。 可訪(fǎng)問(wèn)性有六種可能的形式。 以下內(nèi)容對(duì)訪(fǎng)問(wèn)修飾符進(jìn)行了匯總。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-499628.html
- public:訪(fǎng)問(wèn)不受限制。
- private:訪(fǎng)問(wèn)僅限于此類(lèi)。
- protected:訪(fǎng)問(wèn)僅限于此類(lèi)或派生自此類(lèi)的類(lèi)。
- internal:僅可訪(fǎng)問(wèn)當(dāng)前程序集(.exe?或?.dll)。
- protected internal:僅可訪(fǎng)問(wèn)此類(lèi)、從此類(lèi)中派生的類(lèi),或者同一程序集中的類(lèi)。
- private protected:僅可訪(fǎng)問(wèn)此類(lèi)或同一程序集中從此類(lèi)中派生的類(lèi)。
演示代碼:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-499628.html
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
namespace?CSharpDemo
{
????class?MyClass
????{
????????//使用靜態(tài)修飾符聲明的字段定義的是靜態(tài)字段。 靜態(tài)字段只指明一個(gè)存儲(chǔ)位置。 無(wú)論創(chuàng)建多少個(gè)類(lèi)實(shí)例,永遠(yuǎn)只有一個(gè)靜態(tài)字段副本。
????????public?static?readonly?double?PI = 3.1415926; //使用 readonly 修飾符聲明只讀字段
????????public?static?readonly?int?area = 100; ?//使用 readonly 修飾符聲明只讀字段
????????//不使用靜態(tài)修飾符聲明的字段定義的是實(shí)例字段。 每個(gè)類(lèi)實(shí)例均包含相應(yīng)類(lèi)的所有實(shí)例字段的單獨(dú)副本。
????????public?int?X { get; set; }
????????public?int?Y { get; set; }
????????//構(gòu)造方法
????????public?MyClass(int?x, int?y) => (X, Y) = (x, y);
????????
????????/*
?????????* 方法是實(shí)現(xiàn)對(duì)象或類(lèi)可執(zhí)行的計(jì)算或操作的成員。 靜態(tài)方法是通過(guò)類(lèi)進(jìn)行訪(fǎng)問(wèn)。 實(shí)例方法是通過(guò)類(lèi)實(shí)例進(jìn)行訪(fǎng)問(wèn)。
?????????*
????????方法可能包含一個(gè)參數(shù)列表,這些參數(shù)表示傳遞給方法的值或變量引用。
????????方法具有返回類(lèi)型,它用于指定方法計(jì)算和返回的值的類(lèi)型。 如果方法未返回值,則它的返回類(lèi)型為 void。
????????方法可能也包含一組類(lèi)型參數(shù),必須在調(diào)用方法時(shí)指定類(lèi)型自變量,這一點(diǎn)與類(lèi)型一樣。 與類(lèi)型不同的是,
????????通??梢愿鶕?jù)方法調(diào)用的自變量推斷出類(lèi)型自變量,無(wú)需顯式指定。
????????在聲明方法的類(lèi)中,方法的簽名必須是唯一的。 方法簽名包含方法名稱(chēng)、類(lèi)型參數(shù)數(shù)量及其參數(shù)的數(shù)量、修飾符和類(lèi)型。
????????方法簽名不包含返回類(lèi)型。
?????????*/
????????public?void?print(int?x,int?y)
????????{
????????????Console.WriteLine("x={0},y={1}", x, y);
????????}
????????//當(dāng)方法主體是單個(gè)表達(dá)式時(shí),可使用緊湊表達(dá)式格式定義方法
????????public?void?print() => Console.WriteLine("hello print()");
????????//參數(shù)用于將值或變量引用傳遞給方法。 方法參數(shù)從調(diào)用方法時(shí)指定的自變量中獲取其實(shí)際值。
????????//有四類(lèi)參數(shù):值參數(shù)、引用參數(shù)、輸出參數(shù)和參數(shù)數(shù)組。
????????// 值參數(shù)對(duì)應(yīng)于局部變量,從為其傳遞的自變量中獲取初始值。 修改值形參不會(huì)影響為其傳遞的實(shí)參。
????????public?void?print(int?x,int?y,int?z)
????????{
????????????Console.WriteLine("x={0},y={1},z={2}", x, y,z);
????????}
????????// 在方法執(zhí)行期間,引用參數(shù)指出的存儲(chǔ)位置與自變量相同。 引用參數(shù)使用 ref 修飾符進(jìn)行聲明
????????public?void?print(ref?int?a,ref?double?b)
????????{
????????????Console.WriteLine("x={0},y={1}", a+100, b+100);
????????}
????????//輸出參數(shù)用于按引用傳遞自變量。 輸出參數(shù)與引用參數(shù)類(lèi)似,不同之處在于,
????????//不要求向調(diào)用方提供的自變量顯式賦值。 輸出參數(shù)使用 out 修飾符進(jìn)行聲明。
????????public?void?print(out?double?a,out?double?b)
????????{
????????????a = 12;
????????????b = 34;
????????????Console.WriteLine("a={0},b={1}", a, b);
????????}
????????//參數(shù)數(shù)組允許向方法傳遞數(shù)量不定的自變量。 參數(shù)數(shù)組使用 params 修飾符進(jìn)行聲明。
????????//參數(shù)數(shù)組只能是方法的最后一個(gè)參數(shù),且參數(shù)數(shù)組的類(lèi)型必須是一維數(shù)組類(lèi)型。
????????public?void?print(string?name,params?string[] hubby)
????????{
????????????string?hbs = "";
????????????for?(int?i = 0; i < hubby.Length; i++)
????????????????hbs += hubby[i] + ",";
????????????Console.WriteLine("name={0},hubby={1}", name, hbs);
????????}
????????//使用 static 修飾符聲明的方法是靜態(tài)方法。 靜態(tài)方法不對(duì)特定的實(shí)例起作用,只能直接訪(fǎng)問(wèn)靜態(tài)成員。
????????public?static?void?printS()
????????{
????????????Console.WriteLine("靜態(tài)方法 printS() 調(diào)用了");
????????}
????????//未使用 static 修飾符聲明的方法是實(shí)例方法。 實(shí)例方法對(duì)特定的實(shí)例起作用,并能夠訪(fǎng)問(wèn)靜態(tài)和實(shí)例成員。
????????//其中調(diào)用實(shí)例方法的實(shí)例可以作為 this 顯式訪(fǎng)問(wèn)。 在靜態(tài)方法中引用 this 會(huì)生成錯(cuò)誤。
????????public?void?printDemo()
????????{
????????????Console.WriteLine("printDemo");
????????}
????????
????}
????/*
?????????* 虛方法、重寫(xiě)方法和抽象方法
?????????* ?虛方法是在基類(lèi)中聲明和實(shí)現(xiàn)的方法,其中任何派生類(lèi)都可提供更具體的實(shí)現(xiàn)。
?????????* ?重寫(xiě)方法是在派生類(lèi)中實(shí)現(xiàn)的方法,可修改基類(lèi)實(shí)現(xiàn)的行為。
?????????* ?抽象方法是在基類(lèi)中聲明的方法,必須在所有派生類(lèi)中重寫(xiě)。 事實(shí)上,抽象方法不在基類(lèi)中定義實(shí)現(xiàn)。
?????????*/
????//抽象類(lèi)
????public?abstract?class?Animal
????{
????????//抽象方法: 只需要申明,不需要實(shí)現(xiàn)
????????public?abstract?void?action();
????????public?virtual?void?run()
????????{
????????????Console.WriteLine("動(dòng)物具有跑的能力!");
????????}
????????
????}
????//實(shí)現(xiàn)類(lèi)
????public?class?dog?: Animal
????{
????????//實(shí)現(xiàn)繼承的抽象類(lèi)
????????public?override?void?action()
????????{
????????????Console.WriteLine("狗具有跑的能力!");
????????}
????????//重寫(xiě)父類(lèi)的虛方法 run()
????????public?override?void?run()
????????{
????????????Console.WriteLine("狗會(huì)跑");
????????}
????????//方法重載:多個(gè)方法同名但是參數(shù)類(lèi)型及次序不同
????????public?void?ablity(Animal a)
????????{
????????????a.run();
????????}
????????public?void?ablity(dog d)
????????{
????????????d.action();
????????}
????}
????//其他類(lèi)型函數(shù)成員:構(gòu)造函數(shù)、屬性、索引器、事件、運(yùn)算符和終結(jié)器。
????public?class?MyList<T>
????{
????????//默認(rèn)容量
????????const?int?DefaultCapacity = 4;
????????T[] _items; //創(chuàng)建數(shù)組
????????int?_count; //數(shù)組元素計(jì)數(shù)
????????public?MyList(int?capacity = DefaultCapacity)
????????{
????????????//實(shí)例化數(shù)組
????????????_items = new?T[capacity];
????????}
????????//返回?cái)?shù)組個(gè)數(shù)
????????public?int?Count => _count;
????????//設(shè)置與獲取數(shù)組容量
????????public?int?Capacity
????????{
????????????get?=> _items.Length; //返回?cái)?shù)組容量
????????????//根據(jù)給定容量是否選擇擴(kuò)容
????????????set
????????????{
????????????????if?(value < _count) value = _count;
????????????????if?(value != _items.Length)
????????????????{
????????????????????//開(kāi)始擴(kuò)容
????????????????????T[] newItems = new?T[value];
????????????????????Array.Copy(_items, 0, newItems, 0, _count);
????????????????????_items = newItems; //把擴(kuò)容后的數(shù)組賦值給已有數(shù)組
????????????????}
????????????}
????????}
????????//索引器,用于返回指定索引處的值,借助索引器成員,可以將對(duì)象編入索引(像處理數(shù)組一樣)。
????????public?T this[int?index]
????????{
????????????get?=> _items[index];
????????????set
????????????{
????????????????//首先檢查傳入的值是否與當(dāng)前元素值相同,如果不同則將_items數(shù)組中指定索引處的元素值設(shè)置為新值
????????????????if?(!object.Equals(_items[index], value))
????????????????{
????????????????????_items[index] = value;
????????????????????OnChanged();
????????????????}
????????????}
????????}
????????//添加元素
????????public?void?Add(T item)
????????{
????????????//容量達(dá)到邊界便進(jìn)行雙倍擴(kuò)容
????????????if?(_count == Capacity) Capacity = _count * 2;
????????????_items[_count] = item;
????????????_count++;
????????????OnChanged();
????????}
????????//在這個(gè)方法內(nèi)部,事件處理程序委托"Changed"被調(diào)用來(lái)觸發(fā)事件,
????????//如果已注冊(cè)事件處理程序,則傳遞"EventArgs.Empty"作為參數(shù)。
????????protected?virtual?void?OnChanged() =>
????????????Changed?.Invoke(this, EventArgs.Empty);
????????//該方法首先將other轉(zhuǎn)換為MyList<T>類(lèi)型,然后調(diào)用另一個(gè)Equals方法進(jìn)行比較。
????????public?override?bool?Equals(object?other) =>
????????????Equals(this, other as?MyList<T>);
????????/*
?????????* 這段代碼實(shí)現(xiàn)了一個(gè)自定義類(lèi)型MyList的相等比較函數(shù)Equals。MyList包含一個(gè)整型成員變量_count和數(shù)組成員變量_items,
?????????* 其中_count表示數(shù)組_items中元素的個(gè)數(shù)。
?????????函數(shù)的主要思路是,首先判斷兩個(gè)MyList對(duì)象是否有一個(gè)為null,如果都為null則認(rèn)為它們相等;否則判斷它們的_count是否
????????相等,如果不同則認(rèn)為它們不相等;最后遍歷兩個(gè)MyList對(duì)象中的所有元素,逐一比較它們的值是否相等,如果存在不相等的
????????元素,則認(rèn)為它們不相等。
????????該函數(shù)使用了C#中的object.Equals方法來(lái)判斷兩個(gè)對(duì)象是否相等,這個(gè)方法會(huì)在運(yùn)行時(shí)根據(jù)對(duì)象的實(shí)際類(lèi)型調(diào)用相應(yīng)的
????????比較函數(shù)。對(duì)于數(shù)組類(lèi)型,object.Equals會(huì)逐元素比較數(shù)組中的值是否相等。
?????????*/
????????static?bool?Equals(MyList<T> a, MyList<T> b)
????????{
????????????if?(Object.ReferenceEquals(a, null)) return?Object.ReferenceEquals(b, null);
????????????if?(Object.ReferenceEquals(b, null) || a._count != b._count)
????????????????return?false;
????????????for?(int?i = 0; i < a._count; i++)
????????????{
????????????????if?(!object.Equals(a._items[i], b._items[i]))
????????????????{
????????????????????return?false;
????????????????}
????????????}
????????????return?true;
????????}
????????//申明事件
????????public?event?EventHandler Changed;
????????//運(yùn)算符重載
????????public?static?bool?operator?==(MyList<T> a, MyList<T> b) =>
????????????Equals(a, b);
????????public?static?bool?operator?!=(MyList<T> a, MyList<T> b) =>
????????????!Equals(a, b);
????}
}
代碼使用:
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
namespace?CSharpDemo
{
????//定義枚舉
????public?enum?Seasons
????{
????????None = 0,
????????Summer = 1,
????????Autumn = 2,
????????Winter = 4,
????????Spring = 8,
????????All = Summer | Autumn | Winter | Spring
????}
????class?Program
????{
????????static?void?Main(string[] args)
????????{
????????????MyClass m = new?MyClass(11, 12);
????????????
????????????m.print(11, 12);//值類(lèi)型方法
????????????m.print();//普通方法
????????????m.print(12, 23, 34); //值類(lèi)型參數(shù)
????????????int?a = 12;
????????????Double c = 12.34;
????????????m.print(ref?a, ref?c); //引用類(lèi)型
????????????m.print(12, 34); //輸出類(lèi)型
????????????string?[]hubby = { "籃球","排球","編程","象棋"};
????????????m.print("小劉", hubby); //參數(shù)數(shù)組
????????????MyClass.printS();//靜態(tài)方法
????????????m.printDemo(); //實(shí)例方法: 用指定的對(duì)象調(diào)用
????????????dog d = new?dog(); //實(shí)現(xiàn)抽象類(lèi)的類(lèi)
????????????d.action();
????????????d.run();
????????????Animal animal = new?dog();
????????????//調(diào)用重載的方法
????????????d.ablity(animal);
????????????d.ablity(d);
????????????
????????????MyList<int> list = new?MyList<int>();
????????????//使用委托管理事件
????????????list.Changed += new?EventHandler(ListChanged);
????????????//使用及獲取屬性
????????????list.Capacity = 20;
????????????int?count = list.Count;
????????????int?capcity = list.Capacity;
????????????list.Add(12);
????????????list.Add(34);
????????????//索引器
????????????for(int?i=0;i<list.Count;i++)
????????????Console.WriteLine(list[i]);
????????????Console.WriteLine("事件方法調(diào)用次數(shù){0}", changeCount);
????????????Console.ReadLine();
????????}
????????//事件計(jì)數(shù)
????????static?int?changeCount;
????????//事件的方法
????????static?void?ListChanged(object?sender,EventArgs e)
????????{
????????????changeCount++;
????????}
????}
}
到了這里,關(guān)于C#程序結(jié)構(gòu)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!