⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comparableobject.cs

📁 Data Structures and Algorithms with Object-Oriented Design Patterns in C# 这本书的范例代码dll自己反编译的source
💻 CS
字号:
namespace Opus6
{
    using System;

    [Version("$Id: ComparableObject.cs,v 1.7 2001/10/28 19:50:09 brpreiss Exp $"), Copyright("Copyright (c) 2001 by Bruno R. Preiss, P.Eng.")]
    public abstract class ComparableObject : IComparable
    {
        protected ComparableObject()
        {
        }

        private int Compare(object obj)
        {
            if (base.GetType() == obj.GetType())
            {
                return this.CompareTo(obj);
            }
            return base.GetType().FullName.CompareTo(obj.GetType().FullName);
        }

        public abstract int CompareTo(object obj);
        public override bool Equals(object obj)
        {
            return (this.Compare(obj) == 0);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public static void Main()
        {
            ComparableObject obj1 = (ComparableObject) 0x39;
            ComparableObject obj2 = (ComparableObject) 0x16;
            ComparableObject obj3 = (ComparableObject) "hello";
            int num1 = (int) obj1;
            int num2 = (int) obj2;
            string text1 = (string) obj3;
            Opus6.Console.WriteLine("c1= {0}, i1 = {1}", obj1, num1);
            Opus6.Console.WriteLine("c2= {0}, i2 = {1}", obj2, num2);
            Opus6.Console.WriteLine("c3= {0}, s3 = {1}", obj3, text1);
            Opus6.Console.WriteLine("c1<c2={0}", obj1 < obj2);
            Opus6.Console.WriteLine("c1<c3={0}", obj1 < obj3);
        }

        public static bool operator ==(ComparableObject c, object o)
        {
            if ((c == null) || (o == null))
            {
                return (c == o);
            }
            return (c.Compare(o) == 0);
        }

        public static explicit operator char(ComparableObject c)
        {
            return (char) ((ComparableChar) c);
        }

        public static explicit operator double(ComparableObject c)
        {
            return (double) ((ComparableDouble) c);
        }

        public static explicit operator int(ComparableObject c)
        {
            return (int) ((ComparableInt32) c);
        }

        public static explicit operator string(ComparableObject c)
        {
            return (string) ((ComparableString) c);
        }

        public static bool operator >(ComparableObject c, object o)
        {
            return (c.Compare(o) > 0);
        }

        public static bool operator >=(ComparableObject c, object o)
        {
            return (c.Compare(o) >= 0);
        }

        public static implicit operator ComparableObject(char c)
        {
            return new ComparableChar(c);
        }

        public static implicit operator ComparableObject(double d)
        {
            return new ComparableDouble(d);
        }

        public static implicit operator ComparableObject(int i)
        {
            return new ComparableInt32(i);
        }

        public static implicit operator ComparableObject(string s)
        {
            return new ComparableString(s);
        }

        public static bool operator !=(ComparableObject c, object o)
        {
            if ((c == null) || (o == null))
            {
                return !(c == o);
            }
            return (c.Compare(o) != 0);
        }

        public static bool operator <(ComparableObject c, object o)
        {
            return (c.Compare(o) < 0);
        }

        public static bool operator <=(ComparableObject c, object o)
        {
            return (c.Compare(o) <= 0);
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -