摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 学习{ class 接口 { } //c#是单继承的,一个类只能从一个父类继承,但接口是多实现的,一个类可以用来实现多个接口 public interface Walkable { void Walk(); } public interface Flayble //定义一个接口 { void Fly();//创建这个接口的方法,但不... 阅读全文
posted @ 2012-04-18 07:38 xinyebs 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 参数数组的应用场景:它允许我们在调用一个方法时提供数量可变的参数,而不是由方法事先固定好的数量一个例子:有时候路径中的文件夹数量是大于一的,调用者希望将额外的文件夹关联起来,以构成一个完整的路径,那么如何编码呢?using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 学习{ class 参数数组 { public static void MyParams(params string[] paths) { s... 阅读全文
posted @ 2012-04-12 09:25 xinyebs 阅读(313) 评论(0) 推荐(0) 编辑
摘要: 在c#中multicast委托实现一个通用的模式,目的是避免大量的手工代码,这个模式成为observer或者是publish-subscribe模式,它要应对这样一种情形:你需要将单一的事件通知(比如对象状态发生的一个变化)广播给多个订阅者。 下面以一个温度控制的例子,在这个假象的情形中,一个加热器(heater)一个冷却器(cooler)连接到一个自动调温器。为了控制加热器和冷却器的打开和关闭,要向他们通知温度的变化,调温器自动将温度的变化发布给多个订阅者--也就是加热器和冷却器。首先定义加热器(Herter)using System;using System.Coll... 阅读全文
posted @ 2012-04-09 10:03 xinyebs 阅读(628) 评论(0) 推荐(0) 编辑
摘要: 所谓冒泡排序就是将相邻两个数进行比较,讲较小的掉到前头。namespace ConsoleApplication1{ class 委托和事件 { public static void arraySort(int[] items)//传递的是整形数组 { int i, j, item; for (i = 0; i <= items.Length - 1; i++) { for (j = 0; j <items.Length - 1 - i; j++) ... 阅读全文
posted @ 2012-04-06 23:03 xinyebs 阅读(253) 评论(0) 推荐(0) 编辑
摘要: C# 程序可由一个或多个文件组成。每个文件都可以包含零个或零个以上的命名空间。一个命名空间除了可包含其他命名空间外,还可包含类、结构、接口、枚举、委托等类型。以下是 C# 程序的主干,它包含所有这些元素。// A skeleton of a C# program using System;namespace YourNamespace{ class YourClass { } struct YourStruct { } interface IYourInterface { } delegate int YourDelegate();... 阅读全文
posted @ 2012-04-05 16:32 xinyebs 阅读(148) 评论(0) 推荐(0) 编辑