新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
選擇C#構(gòu)造函數(shù)描述
學(xué)習(xí)C#語言時(shí),經(jīng)常會(huì)遇到選擇C#構(gòu)造函數(shù)問題,這里將介紹選擇C#構(gòu)造函數(shù)問題的解決方法。

選擇C#構(gòu)造函數(shù)
基類對象總是在任何派生類之前構(gòu)造的。因此基類的構(gòu)造函數(shù)在派生類的構(gòu)造函數(shù)之前執(zhí)行。如果基類有多個(gè)構(gòu)造函數(shù),派生類就可以決定要調(diào)用的構(gòu)造函數(shù)。例如,我們可以修改我們的 Point 類來添加第二個(gè)構(gòu)造函數(shù):
- public class Point
- {
- private int x, y;
- public Point()
- {
- x = 0; y = 0;
- }
- public Point(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- }
然后,通過使用 base 關(guān)鍵字,我們可以將 ColorPoint 類更改為使用某個(gè)特定的選擇C#構(gòu)造函數(shù):
- public class ColorPoint : Point
- {
- private Color color;
- public ColorPoint(int x, int y) : base (x, y)
- {
- color = Color.Red;
- }
- }
在 Java 中,這項(xiàng)功能是通過 super 關(guān)鍵字來實(shí)現(xiàn)的。
【編輯推薦】
- C# SystemMenu類介紹
- C# VSProject對象基礎(chǔ)介紹
- C#創(chuàng)建Web應(yīng)用程序項(xiàng)目剖析
- C#調(diào)用Windows服務(wù)項(xiàng)目基礎(chǔ)描述
- C#建立項(xiàng)目簡單分析
文章名稱:選擇C#構(gòu)造函數(shù)描述
轉(zhuǎn)載來于:http://www.fisionsoft.com.cn/article/djjjpsj.html


咨詢
建站咨詢
