System.Enum.CompareTo C# (CSharp) Метод

CompareTo() публичный Метод

public CompareTo ( Object target ) : int
target Object
Результат int
        public int CompareTo(Object target)
        {
            const int retIncompatibleMethodTables = 2;  // indicates that the method tables did not match
            const int retInvalidEnumType = 3; // indicates that the enum was of an unknown/unsupported unerlying type
            
            if (this == null)
                throw new NullReferenceException();
        
            int ret = InternalCompareTo(this, target);

            if (ret < retIncompatibleMethodTables) 
            {
                // -1, 0 and 1 are the normal return codes
                return ret;
            }
            else if (ret == retIncompatibleMethodTables)
            {
                Type thisType = this.GetType();
                Type targetType = target.GetType();

                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_EnumAndObjectMustBeSameType"), 
                        targetType.ToString(), thisType.ToString()));
            }
            else
            {
                // assert valid return code (3)
                BCLDebug.Assert(ret == retInvalidEnumType, "Enum.InternalCompareTo return code was invalid");
                
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
            }
        }
        #endregion

Usage Example

Пример #1
0
        public override void Draw()
        {
            if (_data != null)
            {
                Enum tmp_data = _data;
                _data = EView.EnumPopup(_world_pos, _data);

                if (_data.CompareTo(tmp_data) != 0 && change_action != null)
                {
                    change_action(_data);
                }
            }
        }
All Usage Examples Of System.Enum::CompareTo