zoukankan      html  css  js  c++  java
  • 从0开始学习C#第四天

    昨天老丈人生日,祝他生日快乐,身体健康,洪福齐天!今天补上昨天学习的东西。

    这几天学习有点慢,慢慢学习啦。现在在看C# 的中间件,我比较喜欢Cool 的编程界面!当年的VI

    找到一个比较好的风格配置网站:http://studiostyl.es/不过要用代理上去,哈哈~~,继续学习!

    zy31
    1、理解什么是运算符重载。
    2、掌握运算符重载的程序设计方法。
    3、通过运算符的重载程序设计,进一步感受相关的面向对象编程思想。

    namespace 运算符的重载
    {
        class program 
        {
            static void Main(string[] args) {
                Complex z1 = new Complex(73, 89);
                Complex z2 = new Complex(21,16);
                Complex z3 = Complex.Add(z1, z2);
                //Complex z3= new Complex(z1.a+z2.a,z1.b+z2.b);
                Console.WriteLine("z1+z2={0}+{1}i",z3.a,z3.b);
            }
        
        }
        class Complex {
            public double a, b;
            public Complex(double real,double imagi){
            a=real;
            b=imagi;
            }
            public static Complex Add(Complex z1,Complex z2){
                return new Complex(z1.a+z2.a,z1.b+z2.b);
            
            }
        }
    }
    
    namespace 运算符的重载
    {
        class program 
        {
            static void Main(string[] args) {
                Complex z1 = new Complex(73, 89);
                Complex z2 = new Complex(21,16);
                Complex z3 = z1 + z2;
                //Complex z3= new Complex(z1.a+z2.a,z1.b+z2.b);
                Console.WriteLine("z1+z2={0}+{1}i",z3.a,z3.b);
                Complex z4 = z1 -z2;
                Console.WriteLine("z1-z2={0}+{1}i", z4.a, z4.b);
                Complex z5 = z1 * z2;
                Console.WriteLine("z1*z2={0}+{1}i", z5.a, z5.b);
                Complex z6 = z1 / z2;
                Console.WriteLine("z1/z2={0}+{1}i", z6.a, z6.b);           
    
            }
        
        }
        class Complex {
            public double a, b;
            public Complex(double real, double imagi)
            {
                a = real;
                b = imagi;
            }
           //加法
            public static Complex operator +(Complex z1, Complex z2)
            { return Add(z1, z2); }
    
            public static Complex Add(Complex z1, Complex z2)
            {
                return new Complex(z1.a + z2.a, z1.b + z2.b);
    
            }
            //减法
            public static Complex operator -(Complex z1, Complex z2) 
            { return Sub(z1,z2); }
    
            public static Complex Sub(Complex z1,Complex z2)
            {
                return new Complex(z1.a-z2.a,z1.b-z2.b);
            
            }
            //乘法
            static public Complex operator *(Complex z1, Complex z2) { return Multiply(z1,z2); }
            public static Complex Multiply (Complex z1,Complex z2){
            Complex z=new Complex(0,0);
                z.a=z1.a*z2.a-z1.b*z2.b;
                z.b=z1.b*z2.a+z1.a*z2.b;
                return z;
            }
            //除法
            static public Complex operator /(Complex z1, Complex z2) { return Divide(z1, z2); }
            static public Complex Divide(Complex z1, Complex z2) {
                Complex z = new Complex(0,0);
                double denominator = z2.a * z2.a + z2.b * z2.b;
                z.a = (z1.a * z2.a + z1.b * z2.b) / denominator;
                z.b = (z1.b * z2.a - z1.a * z2.b) / denominator;
                return z;
            }
    
        }
    }
    



    zy32
    1、理解this关键字,并掌握this关键字在程序设计中的用法。
    2、掌握数组在方法中的传递过程。
    3、掌握数组在属性中的传递过程。

    namespace this关键字
    {
        class program 
        {
            static void Main(string []args )
            {
                Time time1 = new Time(2, 32, 23);
                Console.WriteLine(time1.hour);
                Console.WriteLine(time1.minute);
                Console.WriteLine(time1.second);
            }
        }
        class Time {
            public int hour;
            public int minute;
            public int second;
            public Time(int hour ,int minute,int second) 
            {
                
                this.hour = hour;//this 意思:就是“对象”
                this.minute = minute;
                this.second = second;         
              }
        }
    
    }
    
    namespace this关键字
    {
        class program 
        {
           static void Main(string []args){
               At ced = new At();
               int[] arr2 = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
               ced.Arr(arr2);
               Console.WriteLine(ced.arr[3]);
           }
        }
    
        class At
        {
        public int[]arr=new int[9];
        public void Arr(int[] arr1) 
        {
            arr = arr1;
           }
        }
    
    }
    
    namespace this关键字
    {
        class program 
        {
           static void Main(string []args)
           {
               At ced = new At();
               int[] arr1 = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
               ced.Arr=arr1;
               Console.WriteLine(ced.arr[3]);
           }
        }
        class At
        {
            public int[] arr = new int[9];
            public int[] Arr
            {
                //get {}//只读
                set { arr = value; } //只写
            }
        }
    }
    


    zy33
    1、如何定义和使用索引器。
    2、了解索引器和对象数组的区别。
    3、通过索引器访问离散字段。
    4、了解ToLower()函数和null关键字。
    5、通过本课的学习养成良好的编程习惯。

    namespace study33索引器
    {
        class Program
        {
            static void Main(string[] args)
            {
                MyIndexer myindexer = new MyIndexer();
                myindexer[2] = 22;
                myindexer[4] = 44;
                for (int i = 0; i <= myindexer.Length; i++) {
                    Console.WriteLine("myindexer[{0}]={1}",i,myindexer[i]);
                }
    
            }
        }
            class MyIndexer
            {
                private int[] arr = new int[5];
                public int this[int index]
                {
                    get {
                        if (index >= 0 && index < 5) return arr[index];
                        else return 0;
                    }
                    set { 
                        if(index>=0&& index<5) arr[index]=value;
                    }
                }
                public int Length
                {
                    get { return arr.Length; }
                }
            }
    }
    

      


    zy34
    1、了解栈和堆,以及栈的内存存储形式。
    2、了解栈和堆的关系、区别。
    3、认识值类型和引用类型。
    4、通过一个程序理解对象引用符,并知道对象引用符的用法。
    5、实践操作一下类视图。

    zy35
    1、理解什么是继承,什么是基类,什么是派生类。以及它们的关系。
    2、通过一个程序来编写基类和派生类,让理论升华到实践。

    zy36
    1、理解protected保护成员的用法。以及和private及public的区别。
    2、如何在基类中定义虚方法和在派生类中重写虚方法。怎么使用虚方法。
    3、了解重载和重写的区别。

    zy37
    1、掌握普通方法隐藏的程序设计。
    2、利用base关键字调用基类方法。
    3、掌握抽象方法和抽象类的程序设计。
    4、如何密封类和方法。

    zy38
    1、掌握派生类中无参构造函数和有参构造函数的编程方法。
    2、认识Object类,并掌握Object类中的ToString()方法的使用,以及重写该方法。

    zy39
    1、理解多态,掌握多态基本编程思想。
    2、掌握is运算符的用法。

    zy40
    1、掌握基类转换为派生类向下类型的转换。
    2、掌握as运算符的用法。
    3、如何定义和使用接口。

  • 相关阅读:
    [POJ1743]Musical Theme
    [HDU5343]MZL's Circle Zhou
    [ZJOI2015]诸神眷顾的幻想乡
    [SDOI2016]生成魔咒
    [POI2000]Repetitions
    [SPOJ-NSUBSTR]Substrings
    [SPOJ-LCS2]Longest Common Substring II
    [SPOJ-LCS]Longest Common Substring
    [SDOI2010]地精部落
    [HNOI2003]消防局的设立
  • 原文地址:https://www.cnblogs.com/develop/p/3393587.html
Copyright © 2011-2022 走看看