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#基础入门-常量详解

详细介绍data url生成工具C#版第二版的示例代码

详细介绍C# 利用irawpixels接口遍历栅格数据的代码实例

C#构建分页应用的实例方法分析

简单介绍C#中list<t>对象的深度拷贝问题

关于C#中三个关键字params,ref,out的详细介绍

C#中把image无损转换为icon的实例详解

C#中的数据类型是什么?C#中的四种数据类型解释

unity3d用什么语言开发?

C#图片按比例缩放的示例代码分享

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




打赏

取消

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

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

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

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

评论

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