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#实现的md5加密功能与用法示例

详细介绍C#该行已经属于另一个表的解决方法

页面包含处理实例详解

深入理解C#rx的主要接口

具体介绍C#将指定网页添加到收藏夹的方法

C#实现原图片转缩略图

C#从枚举值获取对应文本的图文代码详解

C#二进制字节数组操作函数 截取字节数组subbyte的示例代码

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

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




打赏

取消

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

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

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

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

评论

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