C#接口(Interface)


当前第2页 返回上一页

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

31

32

33

34

35

36

37

38

39

40

41

using System.Collections.Generic;using System.Linq;

using System.Text;using System;namespace InterfaceApplication{ 

public interface ITransactions   {     

// interface members     

void showTransaction();     

double getAmount();  

}    

public class Transaction : ITransactions   {     

private string tCode;     

private string date;     

private double amount;     

public Transaction()      {        

tCode = " ";        

date = " ";        

amount = 0.0;     

}           

public Transaction(string c,string d, double a)      {        

tCode = c;        

date = d;        

amount = a;     

}           

public double getAmount()      {        

return amount;      }           

public void showTransaction()     

{        

Console.WriteLine("Transaction: {0}", tCode);        

Console.WriteLine("Date: {0}", date);        

Console.WriteLine("Amount: {0}", getAmount());     

}  

}  

class Tester   {     

static void Main(string[] args)     

{        

Transaction t1 = new Transaction("001", "8/10/2012", 78900.00);       

Transaction t2 = new Transaction("002", "9/10/2012", 451900.00);        

t1.showTransaction();        

t2.showTransaction();        

Console.ReadKey();     

}  

}

}

当上面的代码被编译和执行时,它会产生下列结果:

1

Transaction: 001Date: 8/10/2012Amount: 78900Transaction: 002Date: 9/10/2012Amount: 451900

以上就是C#接口(Interface)的内容!


返回前面的内容

相关阅读 >>

C#教程】C# 多态性

C#中将字符串内容写入到txt文件中

C#日期格式转换的公共方法类的实现详解

C#设计模式-观察者模式的另类的示例代码总结

C#实现带百分比的进度条功能的示例代码分享

C#中关于new的用法以及和override的区别分析详解

C#如何使用 oledbconnection 连接读取excel?(代码实例)

C#高级编程(一)-.net体系结构

C#操作iis创建应用程序池出现异常:无效索引的解决方法

利用unity脚本自定义分辨率实现相机截一张高清截图

更多相关阅读请进入《C#》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...