コード例 #1
0
        public bool Equals(SimpleDateTime dTime)
        {
            // Check for null.
            if (dTime == null)
            {
                return(false);
            }

            // Check for ReferenceEquals if this is a reference type.
            if (ReferenceEquals(this, dTime))
            {
                return(true);
            }

            // Possibly check for equivalent hash codes.
            if (this.GetHashCode() != dTime.GetHashCode())
            {
                return(false);
            }

            // Check base.Equals if base overrides Equals().
            System.Diagnostics.Debug.Assert(base.GetType() != typeof(object));

            if (!base.Equals(dTime))
            {
                return(false);
            }

            // Compare identifying fields for equality.
            return(this.year.Equals(dTime.year) && this.month.Equals(dTime.month) && this.day.Equals(dTime.day) && this.hour.Equals(dTime.hour) && this.minute.Equals(dTime.minute) && this.second.Equals(dTime.second));
        }
コード例 #2
0
        public int CompareTo(object obj)
        {
            if (!(obj is SimpleDateTime))
            {
                throw new ArgumentException("object is not a SimpleDateTime");
            }

            SimpleDateTime st2 = obj as SimpleDateTime;

            // Start off assuming a result of equality (zero).
            int result = 0;

            // Work our way through testing year, month, day, hour, minute, second.
            if (this.year > st2.year)
            {
                result = 1;
            }
            else if (this.year < st2.year)
            {
                result = -1;
            }
            else if (this.month > st2.month)
            {
                result = 1;
            }
            else if (this.month < st2.month)
            {
                result = -1;
            }
            else if (this.day > st2.day)
            {
                result = 1;
            }
            else if (this.day < st2.day)
            {
                result = -1;
            }
            else if (this.hour > st2.hour)
            {
                result = 1;
            }
            else if (this.hour < st2.hour)
            {
                result = -1;
            }
            else if (this.minute > st2.minute)
            {
                result = 1;
            }
            else if (this.minute < st2.minute)
            {
                result = -1;
            }
            else if (this.second > st2.second)
            {
                result = 1;
            }
            else if (this.second < st2.second)
            {
                result = -1;
            }

            return(result);
        }