c# Base關(guān)鍵字的使用
更新時(shí)間:2009年07月26日 21:50:56 作者:
c# Base關(guān)鍵字的使用示例代碼,大家可以參考下用法。
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class 繼承1
{
//virtual虛函數(shù),這樣寫便于子類重寫
public virtual double Area(double a)
{
return a * 2;
}
}
class Test : 繼承1
{
//重寫父類的Area,當(dāng)然也可以調(diào)用父類的Area方法
public override double Area(double b)
{
//關(guān)鍵字base.Area()調(diào)用了父類的Area方法
return base.Area(b) * 0.9;
}
}
class Result
{
static void Main()
{
Test TT = new Test();
Console.WriteLine(TT.Area(10));
}
}
}
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Class4
{
//申明2個(gè)構(gòu)造函數(shù)
public Class4()
{
Console.WriteLine("Class4");
}
int i;
public Class4(int a)
{
i=a;
Console.WriteLine("Class:{0}", i);
}
public void SS()
{
Console.WriteLine("BOSS");
}
}
class Test:Class4
{
//調(diào)用父類(無(wú)參數(shù)的)構(gòu)造函數(shù)
public Test()
: base()
{
}
//調(diào)用父類(有參數(shù)的)構(gòu)造函數(shù)
public Test(int a)
: base(a)
{
base.SS();
}
}
class TT
{
static void Main()
{
Test T = new Test();
Test T1 = new Test(10);
}
}
}
相關(guān)文章
C#與PHP的md5計(jì)算結(jié)果不同的解決方法
今天在用C#接入我的登錄api發(fā)現(xiàn)了一個(gè)問(wèn)題,登陸的時(shí)候無(wú)論如何都會(huì)出現(xiàn)用戶名和密碼錯(cuò)誤的問(wèn)題,后來(lái)通過(guò)查找排除找的了問(wèn)題的原因是因?yàn)镃#與PHP的md5計(jì)算結(jié)果不同導(dǎo)致的,下面就來(lái)看看如何解決這個(gè)問(wèn)題吧。2016-12-12淺析C# web訪問(wèn)mysql數(shù)據(jù)庫(kù)-整理歸納總結(jié)
本篇文章是對(duì)C#中的web訪問(wèn)mysql數(shù)據(jù)庫(kù)的一些知識(shí)點(diǎn)進(jìn)行了整理歸納總結(jié),需要的朋友可以參考下2013-07-07WPF調(diào)用ffmpeg實(shí)現(xiàn)屏幕錄制
這篇文章主要為大家詳細(xì)介紹了WPF如何調(diào)用ffmpeg實(shí)現(xiàn)屏幕錄制,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,感興趣的小伙伴可以了解一下2023-05-05