重新学习基础:草稿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);
        }

    }
}

原文地址:https://www.cnblogs.com/handboy/p/7148464.html