c# Base關鍵字的使用
更新時間:2009年07月26日 21:50:56 作者:
c# Base關鍵字的使用示例代碼,大家可以參考下用法。
復制代碼 代碼如下:
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,當然也可以調(diào)用父類的Area方法
public override double Area(double b)
{
//關鍵字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));
}
}
}
復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Class4
{
//申明2個構(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)用父類(無參數(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);
}
}
}
相關文章
淺析C# web訪問mysql數(shù)據(jù)庫-整理歸納總結(jié)
本篇文章是對C#中的web訪問mysql數(shù)據(jù)庫的一些知識點進行了整理歸納總結(jié),需要的朋友可以參考下2013-07-07