# 抽象函数abstract
1.抽象函数可以有实例成员,public int age{get;set;}
2.抽象函数不能有任何实现 public abstract void say()
3.抽象成员必出包含在抽象类中
4.抽象类不能实例化任何对象,只能用来继承
5.继承抽象类的子类必须把抽象成员出重写override,除非子类也是抽象类
abstract class myclass
{
public int age{get;set;}
public abstract void say()
}
class myclass1:myclass
{
public override void say()
{
console.writeLine("123")
}
}
myclass my=new myclass1
my.say()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 接口:(不能实例实例化)
接口就是一种规范协议
1.接口以I开头
2接口里能包含方法,属性,索引器和事件,实际都是方法
3.所有不能写访问修饰符,默认public
4.能继承多个接口,但只能继承一个父类
public interface Ifly
{
方法
void sayhi();
void sayhi(string aaa);
属性(表示一个未实现属性)
string name{get:set}
索引器
string this[int index]{get;set;}
}
*实现接口和显示实现接口
class my:If1,If2
{
实现接口
public void fly(){}
显示实现接口(不能有修饰符, 相对类是private, 接口是public)
void If2.fly(){}
}
my m=new my
m.fly 是实现接口
If1 f1=new my
f1.fly 是实现接口
If2 f2=new my
f2.fly 是显示实现接口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30