zoukankan      html  css  js  c++  java
  • 复习整理

        #region 多态继承
        public abstract class animal
        {
            public    void Eat()
            {
                Console.WriteLine("animal Eat");
            }
            public virtual void Call()
            {
                Console.WriteLine("animal Call");
            }
            public abstract void live();
        }
        public class cat : animal
        {
            public override void Call()
            {
                Console.WriteLine("cat Call");
            }
            public override void live()
            {
                Console.WriteLine("the cat is live");
            }
        }
        public class dog : animal
        {
            public     void Eat()
            {
                Console.WriteLine("dog Eat");
            }
            public override void live()
            {
                Console.WriteLine("the dog is live");
            }
        }
    
        #endregion
    View Code

    多态。。

    重写,重载,abstract,override,virtual

    abstract :无实体函数,子类必须实现

    virtual:有实体函数,子类可以不实现,如果实现实为覆盖;

    如果不标注virtual的函数被子类实现了,那么子类的函数与父类并存,且实现的时候不需要加override修饰

        #region 多态继承
        public abstract class animal
        {
            public    void Eat()
            {
                Console.WriteLine("animal Eat");
            }
            public virtual void Call()
            {
                Console.WriteLine("animal Call");
            }
        }
        public class cat : animal
        {
            public override void Call()
            {
                Console.WriteLine("cat Call");
            }
        }
        public class dog : animal
        {
            public     void Eat()
            {
                Console.WriteLine("dog Eat");
            }
        }
    
        #endregion
    View Code

    这个代码是.NET传参数的方式,ref,out,params

    REF:传参数前先赋值

    OUT:返回前必须赋值

    params:无限制的传参数,随便多少个都无所谓

        public class CloneString : ICloneable
        { 
            public int intI = 1234;
            public Car aCar = new Car();
            public object Clone()
            {
                CloneString cs= new CloneString(); 
                cs.intI = intI;
                cs.aCar.CarName = aCar.CarName;
                cs.aCar.CarNum = aCar.CarNum;
                return cs;
            }
            public object MemberwishClone()
            {
                return base.MemberwiseClone();
            }
            public override string ToString()
            {
                return "CarNum:" + aCar.CarNum + "aCar.CarName:" + aCar.CarName;
            }
        }
    
        public class Car
        {
            public string CarName = "hongqi";
            public int CarNum =  10010 ;
        
        }
    View Code

    深复制。复制引用类型和值类型

      //这个类测试属性
        public class student
        {
            protected string _name = "";
            public string Name
            {
                set { _name = value; }
                get
                {
                    if (_name == "wsenmin") return _name + " you are best student!";
                    else return _name + " you are not wsenmin !";
                }
            }
        }
    View Code

    属性,方便代码扩展,让字段不暴露

        public class people
        {
            protected string _name = "";
            protected int _age = 0;
    
            public people(string name, int age)
            {
                Name = name;
                Age = age;
            }
            public string Name
            {
                set { _name = value; }
                get
                {
                    return _name;
                }
            }
            public int Age
            {
                set { _age = value; }
                get
                {
                    return _age;
                }
            }
            public string SayHello()
            {
                return Name + "对你说 “你好”";
            }
    
        }
        /// <summary>
        /// 索引测试
        /// </summary> 
        public class PeopleS
        {
    
            people[] ps = new people[4];
            public PeopleS()
            {
                ps[0] = new people("a", 1);
                ps[1] = new people("b", 132);
                ps[2] = new people("c", 32);
                ps[3] = new people("wsenmin", 27);
            }
    
            public people this[int index]
            {
                get { return ps[index]; }
            }
    
            public people this[string name]
            {
                get
                {
                    for (int i = 0; i < ps.Length; i++)
                    {
                        if (name == ps[i].Name) { return ps[i]; }
                    }
                    return null;
                }
            }
    
        }
    View Code

    索引器,很简单的查找和匹配

    using:类似于try catch finally ,自动调用dispose方法

  • 相关阅读:
    Android事件详解——拖放事件DragEvent
    Android 用户界面---拖放(Drag and Drop)(三)
    Android 用户界面---拖放(Drag and Drop)(二)
    Android 用户界面---拖放(Drag and Drop)(一)
    Android开发者指南-用户界面-拖放-Drag and Drop[原创译文]
    Android L动画入门
    基本介绍LINUX远程PC软件:PUTTY、SecureCRT、X-Manager
    js字的数目的计算方法(与word计算公式为)
    动机,努力工作,提高能力,提高战斗力,要注意保暖,维护创业热情。
    pig询问top k,每个返回hour和ad_network_id最大的两个记录(SUBSTRING,order,COUNT_STAR,limit)
  • 原文地址:https://www.cnblogs.com/jacd/p/3100731.html
Copyright © 2011-2022 走看看