博文

C#学习笔记 (2006-01-12 21:53:00)

摘要:  1.  重点放在c#和c++不同的地方,比如接口,代理,对象索引,事件,sealed等 2.     事件(EVENT)是一个很好的概念。它将传统IDE里面事件驱动程序的思想加入到语言层面支持上来。结合delegate将对象相应的事件和事件处理代码绑定。 3.     c#为什么在支持interface的同时还支持abstract类声明?刚开始觉得既然abstract实际上相当于interface声明,好像两者只需要一个就行了.但是后来考虑有一定的区别,interface完全不提供实现,只是一种接口约定,继承这个接口的类一定要完全实现这些约定的接口实现,而abstract类可以提供部分方法的实现,但是代表抽象概念,无法实例化.一般来说从概念上属于IS-A的类关系应该用ABSTRACT类继承。而如果是MUST-DO类型的应该从interface继承. 4.     C#中的抽象(abstract)类相当于c++中的带有纯虚函数virtual function(para1,para2)=0声明的类。而抽象方法(abstract function(para,…))相当于C++中的纯虚函数.抽象方法在继承类里面不能用base调用父类,这是很显然的,因为抽象方法只是一个声明规范,根本没有实现,所以无从调用. 5.     sealed类声明表明不允许这个类被继承。Sealed方法不允许这个方法被重载。之所以引入sealed类,是为了避免类继承层次过多带来的问题或者某个类根本就没有必要被继承.很明显,在封闭类里面声明方法的时候,virtual是没有意义的,因为virtual从语义上来说是期望被继承的,而这与sealed的语义矛盾. 6.     c#类不支持多继承,但是接口允许多继承。 7.delegate实际上就是指向函数的指针,引入它的目的是为了实现事件驱动编程模式,将事件和事件处理函数连接起来. 8.以后考虑构造实验系统的时候用C#,一方面熟悉语言和......

阅读全文(3711) | 评论:0

C#编写的windows计算器-源代码 (2006-01-04 23:40:00)

摘要:using System;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
using System.Data; namespace comput
{
 /// <summary>
 /// 这是一个计算器的简单实现。
 /// </summary>  public class Form1 : System.Windows.Forms.Form
 {
  #region 控件声明
   
  private System.Windows.Forms.TextBox txtShow;
  private System.Windows.Forms.GroupBox groupBox1;
  private System.Windows.Forms.Button btn_rev;
  private System.Windows.Forms.Button btn_dot;
  private System.Windows.Forms.Button btn_add;
  private System.Windows.Forms.Button btn_equ;
  private System.Windows.Forms.Button btn_sign;
  private System.Windows.Forms.Button btn_sub;
  private System.Windows.Forms.Button btn_mul;
  private System.Windows.Forms.Button ......

阅读全文(2660) | 评论:0