• 重新学习基础:草稿3(2)【后续】


    原文发布时间为:2008-11-24 —— 来源于本人的百度文章 [由搬家工具导入]

    struct Digit
        {
            byte value;

            public Digit(byte value) //constructor
            {
                if (value > 9)
                {
                    throw new System.ArgumentException();
                }
                this.value = value;
            }

            public static implicit operator byte(Digit d) // implicit digit to byte conversion operator
            {
                System.Console.WriteLine("conversion occurred");
                return d.value; // implicit conversion
            }
        }

        public struct Complex
        {
            public int real;
            public int imaginary;

            public Complex(int real, int imaginary) //constructor
            {
                this.real = real;
                this.imaginary = imaginary;
            }

            // Declare which operator to overload (+),
            // the types that can be added (two Complex objects),
            // and the return type (Complex):
            public static Complex operator +(Complex c1, Complex c2)
            {
                return new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary);
            }

            // Override the ToString() method to display a complex number in the traditional format:
            public override string ToString()
            {
                return (System.String.Format("{0} + {1}i", real, imaginary));
            }
        }

        struct Chu
        {
            public int value;
            public Chu(int value)
            {
                this.value = value;
            }
            public static Chu operator /(Chu chu1, Chu chu2)
            {
                return new Chu(chu1.value % chu2.value);
            }

            public override string ToString()
            {
                return value.ToString();
            }
        }
        public abstract class A
        {
            public abstract void DoWork(int i);
        }

        public class D
        {
            public virtual void DoWork(int i)
            {
                // Original implementation.
            }
        }

        public abstract class E : D
        {
            public abstract override void DoWork(int i);
        }

        public class F : E
        {
            public override void DoWork(int i)
            {
                // New implementation.
            }
        }

        // compile with: csc /target:library abstractshape.cs
        public abstract class Shape
        {
            private string m_id;

            public Shape(string s)
            {
                // calling the set accessor of the Id property.
                Id = s;
            }

            public string Id
            {
                get
                {
                    return m_id;
                }

                set
                {
                    m_id = value;
                }
            }

            // Area is a read-only property - only a get accessor is needed:
            public abstract double Area
            {
                get;
            }

            public override string ToString()
            {
                return Id + " Area = " + string.Format("{0:F2}", Area);
            }
        }
        // compile with: csc /target:library /reference:abstractshape.dll shapes.cs
        public class Square : Shape
        {
            private int m_side;

            public Square(int side, string id)
                : base(id)
            {
                m_side = side;
            }

            public override double Area
            {
                get
                {
                    // Given the side, return the area of a square:
                    return m_side * m_side;
                }
            }
        }

        public class Circle : Shape
        {
            private int m_radius;

            public Circle(int radius, string id)
                : base(id)
            {
                m_radius = radius;
            }

            public override double Area
            {
                get
                {
                    // Given the radius, return the area of a circle:
                    return m_radius * m_radius * System.Math.PI;
                }
            }
        }

        public class Rectangle : Shape
        {
            private int m_width;
            private int m_height;

            public Rectangle(int width, int height, string id)
                : base(id)
            {
                m_width = width;
                m_height = height;
            }

            public override double Area
            {
                get
                {
                    // Given the width and height, return the area of a rectangle:
                    return m_width * m_height;
                }
            }
        }

        class Car
        {
            public virtual void DescribeCar()
            {
                System.Console.WriteLine("Four wheels and an engine.");
            }
        }

        // Define the derived classes
        class ConvertibleCar : Car
        {
            public new virtual void DescribeCar()
            {
                base.DescribeCar();
                System.Console.WriteLine("A roof that opens up.");
            }
        }

        class Minivan : Car
        {
            public override void DescribeCar()
            {
                base.DescribeCar();
                System.Console.WriteLine("Carries seven people.");
            }
        }
        interface IControl
        {
            void Paint();
        }
        interface ISurface
        {
            void Paint();
        }
        public class SampleClass2 : IControl, ISurface
        {
            void IControl.Paint()
            {
                System.Console.WriteLine("IControl.Paint");
            }
            void ISurface.Paint()
            {
                System.Console.WriteLine("ISurface.Paint");
            }
        }
        interface ILeft
        {
            int P { get;}
        }
        interface IRight
        {
            int P();
        }
        class Middle : ILeft, IRight
        {
            public int P() { return 0; }
            int ILeft.P { get { return 0; } }
        }

        interface IDimensions
        {
            float getLength();
            float getWidth();
        }
        public class Box : IDimensions
        {
             float lengthInches;
            float widthInches;

            public Box(float length, float width)
            {
              this.lengthInches = length;
              this.widthInches = width;
            }
            // Explicit interface member implementation:
         float IDimensions.getLength()
            {
                return this.lengthInches;
            }
            // Explicit interface member implementation:
          public float getWidth()
            {
                return this.widthInches;
            }
        }
        public class GouZao
        {
            private GouZao()
            {
            }
            public GouZao(int a)
            {
            }
        }


    abstract class Shape2
    {
        public const double pi = System.Math.PI;
        protected double x, y;

        public Shape2(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        public abstract double Area();
    }

    class Circle2 : Shape2
    {
        public Circle2(double radius)
            : base(radius, 0)
        {
        }
        public override double Area()
        {
            return pi * x * x;
        }
    }

        public class Bus
        {
            // Static constructor:
            static Bus()
            {
                System.Console.WriteLine("The static constructor invoked.");
            }

            public static void Drive()
            {
                System.Console.WriteLine("The Drive method invoked.");
            }
            internal void inMethod()
            {
                System.Console.WriteLine("internal!");
            }

        }
        class First:Bus
        {
            ~First()
            {
                inMethod();
                System.Console.WriteLine("First's destructor is called");
            }
        }

        class Second : First
        {
            ~Second()
            {
                System.Console.WriteLine("Second's destructor is called");
            }
        }

        class Third : Second
        {
            ~Third()
            {
                System.Console.WriteLine("Third's destructor is called");
            }
        }

        public partial class CoOrds
        {
            private int x;
            private int y;

            public CoOrds(int x, int y)
            {
                this.x = x;
                this.y = y;
            }
        }

        public partial class CoOrds
        {
            public void PrintCoOrds()
            {
                System.Console.WriteLine("CoOrds: {0},{1}", x, y);
            }

        }
    }

  • 相关阅读:
    详解vue静态资源打包中的坑与解决方案
    vue项目构建实战基础知识:SPA理解/RESTful接口介绍/static目录配置/axios封装/打包时map文件去除
    axios踩坑记录+拦截器使用+vue cli代理跨域proxy+webpack打包部署到服务器
    vue-cli项目开发/生产环境代理实现跨域请求+webpack配置开发/生产环境的接口地址
    vue中watch的用法总结以及报错处理Error in callback for watcher "checkList"
    Vue侦听器watch
    ES6 import 引用文件夹/目录及其处理过程
    Nginx部署前端代码实现前后端分离
    使用XmlInclude解决WebService调用时无法识别子类的异常
    WebServices中Xml的序列化
  • 原文地址:https://www.cnblogs.com/handboy/p/7148464.html
Copyright © 2020-2023  润新知