wIthwInd

-随风而行

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
面向对象
    1、数据封装
    2、代码重用
    3、多态性
    4、重载
命名空间
    using [alias=]namespace;
声明自己的类
    1、封装数据
        private int count;
        ... ...
    2、构造和析构
        构造:public 类名(...) {...},可存在多个
        ~类名:析构,一般不需要
    3、方法
使用自己的类

    静态域:public static int field1;
    只读域:public readonly int field1;
属性
    修饰符 类型 标识符 {代码}
    private string name;
    public string Name
        {
            get{rerurn name;}
            set{name = value;}
        }
索引
    修饰符 类型 this[索引值]
    private int[] Array = new int[5];
    public int this[int index]
        {
            get   
                {
                    rerurn Array[index];
                }
            set
                {
                    Array[index] = value;
                }
        }
重载
    关键是参数不一样
    params:后面不能再有其他参数,因此一般是最后一个参数
    ref、out:实参前也必须加ref、out关键字,ref于out的区别在于out关键字不需要实参必须提前初始化
运算符重载
    语法:public static 返回类型 operator 运算符(参数){代码}
    数据转换也可重载
    语法:public static implicit operator 转换后的类型(被转换的数值)
                public static explicit operator 转换后的类型(被转换的数值)
posted on 2004-10-02 19:45  随风  阅读(357)  评论(0编辑  收藏  举报