抽象类
抽象类中
1.只包含抽象方法,
2.包含非抽象方法和抽象方法
3.可使用get和set访问器
Example 1:
public abstract class GeeksForGeeks {
public abstract void gfg();
}
public class Geek1 : GeeksForGeeks
{
public override void gfg()
{
Console.WriteLine("class Geek1");
}
}
public class Geek2 : GeeksForGeeks
{
public override void gfg()
{
Console.WriteLine("class Geek2");
}
}
Example 2:
abstract class AbstractClass {
public int AddTwoNumbers(int Num1, int Num2)
{
return Num1 + Num2;
}
public abstract int MultiplyTwoNumbers(int Num1, int Num2);
}
class Derived : AbstractClass {
public override int MultiplyTwoNumbers(int Num1, int Num2)
{
return Num1 * Num2;
}
}
Example 3:
abstract class absClass {
protected int myNumber;
public abstract int numbers
{
get;
set;
}
}
class absDerived : absClass {
public override int numbers
{
get
{
return myNumber;
}
set
{
myNumber = value;
}
}
}
转自 https://www.geeksforgeeks.org/c-sharp-abstract-classes/