C#接口
来源:互联网 发布:儿童汉语拼音拼读软件 编辑:程序博客网 时间:2024/06/07 10:04
接口定义了所有类继承接口时应遵循的语法合同。接口定义了语法合同 "是什么" 部分,派生类定义了语法合同 "怎么做" 部分。
接口定义了属性、方法和事件,这些都是接口的成员。接口只包含了成员的声明。成员的定义是派生类的责任。接口提供了派生类应遵循的标准结构。
抽象类在某种程度上与接口类似,但是,它们大多只是用在当只有少数方法由基类声明由派生类实现时。
using System.Collections.Generic;using System.Linq;using System.Text;namespace InterfaceApplication{ public interface ITransactions { // 接口成员 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.showTrans当上面的代码被编译和执行时,它会产生下列结果:
action(); Console.ReadKey(); } }}
Transaction: 001Date: 8/10/2012Amount: 78900Transaction: 002Date: 9/10/2012Amount: 451900
0 0
- C#接口
- C#接口
- C# 接口
- C# 接口
- C#接口
- C# 接口
- C#接口
- C# - 接口
- C#接口
- C#接口
- C#接口
- C# 接口
- C# 接口
- C#接口
- C#接口
- C# 接口
- C# 接口
- C#接口
- nyoj 301 递推求值 矩阵快速幂
- 大规模的程序可能要注意的地方
- HDU 1237 简单计算器
- office 2010 密钥(office 2010永久的密钥)
- ShareX(图片文件分享程序)V11.1.0中文版
- C#接口
- Amazing Slider(网页图片轮播制作)V6.2中文特别版
- 百度站长链接实时提交工具V1.0
- Opencv中.xml和.yml读写
- XGen 苹果IOS神器一键新机改串清理超级全息备份支持IOS789超IGV8使用分享(企鹅290093670)
- 来选择一款适合我网站的CMS建站程序吧?
- office2016永久免费激活码(office2016密钥)
- redhat7.2用户及用户组权限管理操作实例
- Leetcode 307. Range Sum Query - Mutable (Python)