摘要: 目录 类与结构的实例比较 类与结构的差别 如何选择结构还是类一.类与结构的示例比较:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--//結構示例publicstructPerson{//聲明結構Personpr=newPerson();//聲明類Tes... 阅读全文
posted @ 2008-07-29 14:06 Crayon 阅读(264) 评论(0) 推荐(0) 编辑
摘要: ref 关键字使参数按引用传递。其效果是,当控制权传递回调用方法时,在方法中对参数所做的任何更改都将反映在该变量中。若要使用 ref 参数,则方法定义和调用方法都必须显式使用 ref 关键字.class RefExample{ static void Method(ref int i) { i = 44; } static void Main() { int val = 0; Method(ref... 阅读全文
posted @ 2008-07-29 14:03 Crayon 阅读(408) 评论(0) 推荐(0) 编辑
摘要: interface用来声明接口1.只提供一些方法规约,不提供方法主体 如 public interface IPerson{ void getName();//不包含方法主体 }2.方法不能用public abstract等修饰,无字段变量,无构造函数。3.方法可包含参数 如 public interface IPerson { void getAge(string s); } 一个例子(例1):... 阅读全文
posted @ 2008-07-29 13:54 Crayon 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 目录类与结构的实例比较 类与结构的差别 如何选择结构还是类 一.类与结构的示例比较: 结构示例: public struct Person { string Name; int height; int weight public bool overWeight() { //implement something } } 类示例: public class TestTime { int hours;... 阅读全文
posted @ 2008-07-29 13:49 Crayon 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 首先需要注意的是抽象类不能声明为sealed,这两个语义是冲突的。抽象方法不必(也不能)声明为virtual,因为它缺省隐含就为virtual!C#中的abstract类不能被实例化,他只提供其他类的继承的接口using System;abstract class MyAbs{public void NonAbMethod(){Console.WriteLine("Non-Abstract Met... 阅读全文
posted @ 2008-07-29 13:30 Crayon 阅读(964) 评论(0) 推荐(0) 编辑