业精于勤

导航

2012年4月12日

类的继承

摘要: 就一个":" 冒号。类的继承,主要目的是代码的重用。另外,通过类的继承,代码有清晰的组织关系。子类:父类 派生类:基类 看代码classAnimal{publicintweight;publicintage;publicAnimal(){Console.WriteLine("动物的构造方法");}publicAnimal(stringn,intw){name=n;weight=w;}publicvoidSleep(){Console.WriteLine("动物睡觉");}privatestringname;protectedstrin 阅读全文

posted @ 2012-04-12 08:57 言午 阅读(220) 评论(0) 推荐(0) 编辑

2012年4月11日

多态(虚方法)

摘要: 使用虚方法实现“多态”背景:classAnimal{publicstringname;publicintage;publicfloattemperature;publicvoidEat(){Console.WriteLine("Animal吃东西");}}classWolf:Animal{publicstringcolor;publicvoidhunt(){}publicvoidEat(){Console.WriteLine("Wolf吃羊");}}classFish:Animal{publicvoidSwim(){}publicvoidEat(){Co 阅读全文

posted @ 2012-04-11 16:47 言午 阅读(244) 评论(0) 推荐(0) 编辑

事件event

摘要: 委托,是事件基础类的对象,发出消息,在运行时绑定处理方法。以下,以animal为例,体温过高时,触发事件1 先定一个个委托delegatevoidMyDelegate();2 在类中定义事件,并在某时刻触发。此例中在体温属性改变,大于37.5时触发。classAnimal{//定义一个事件体温过高(先定义MyDelegate)publiceventMyDelegatehighTemperature;floattemperature;//体温publicfloatTemperature{get{returntemperature;}set{temperature=value;//体温高时,触发事 阅读全文

posted @ 2012-04-11 15:46 言午 阅读(298) 评论(0) 推荐(0) 编辑

委托 代理

摘要: 委托=代理以前,我们调用方汉,直接 call method 现在,我们使用代理, call->delegate -> method有事,找代理。1 定义一“种”委托delegatevoidMyDelegate(stringn);解释一下,短短的一行代码,信息量巨大。有一个委托,名叫MyDelegate ,它能代理形如 void XXX(string)的方法。2 准备两个方法,过分简单, 不解释 staticvoidSayHello(stringname){Console.WriteLine("Hello,{0}",name);}staticvoidSayBye( 阅读全文

posted @ 2012-04-11 15:28 言午 阅读(165) 评论(0) 推荐(0) 编辑

索引!

摘要: 这个部分内容,一般重要。//索引参照属性 --> 字段成员 1 索引 --> 集合成员 nclassAnimal{privatestringname;publicstringName{get{returnname;}set{name=value;}}privatestring[]names={"张华","小华","华仔","zhanghua"};publicstringthis[intindex]{get{returnnames[index];}set{names[index]=value;}}}索引的 阅读全文

posted @ 2012-04-11 15:17 言午 阅读(156) 评论(0) 推荐(0) 编辑

2012年3月14日

第五周作业

摘要: 1定义一个类,描述一种动物(自选)。要求有字段,方法,有构造方法与析构方法。2 使用这个类,创建实例。访问实便的字例,演示该动物的方法,演示构造方法与析构方法。 阅读全文

posted @ 2012-03-14 16:57 言午 阅读(237) 评论(1) 推荐(0) 编辑

2012年3月8日

第四周作业

摘要: 1 二维数组,定义两个3*3矩阵,完成加法、减法、乘法运算,并输出结果。2 List<T>,参照书上例题,struct stud 结构中加入分数字段。自定义一个List<stud>,回入测试数据,计算数据里的平均分,最高分,最低分。 阅读全文

posted @ 2012-03-08 09:04 言午 阅读(198) 评论(0) 推荐(0) 编辑

2011年12月1日

考试!

摘要: 考试题分:选择 30问答 25编程 45考试内容C# 语言基础面向对象编程类 属性 构造 静态成员 方法 委托 接口 抽象类接口 继承泛型 三层架构多线程asp.net ADO.net 数据库操作 阅读全文

posted @ 2011-12-01 14:43 言午 阅读(168) 评论(0) 推荐(0) 编辑

2011年11月15日

线程安全 二

摘要: usingSystem;usingSystem.Threading;abstractclassCounter{protectedintcount=0;publicabstractintRead(intthreadNum);publicabstractvoidIncrement(intthreadNum);}//NotethattheinstancevariablecountissharedbetweenthetwomethodsRead//andIncrement.Threadsconcurrentlyexecutingoneorbothofthesemethodscan//interfere 阅读全文

posted @ 2011-11-15 11:41 言午 阅读(190) 评论(0) 推荐(0) 编辑

线程安全 一

摘要: usingSystem;usingSystem.Threading;usingSystem.Runtime.Remoting.Contexts;usingSystem.Runtime.CompilerServices;//NotethattheinstancevariablecountissharedbetweenthetwomethodsRead//andIncrement.Threadsconcurrentlyexecutingoneorbothofthesemethodscan//interferewitheachotherunlessactionistakentosynchronize 阅读全文

posted @ 2011-11-15 11:40 言午 阅读(203) 评论(0) 推荐(0) 编辑