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

ToUInt64() приватный статический Метод

private static ToUInt64 ( Object value ) : ulong
value Object
Результат ulong
        private static ulong ToUInt64(Object value)
        {
            // Helper function to silently convert the value to UInt64 from the other base types for enum without throwing an exception.
            // This is need since the Convert functions do overflow checks.
            TypeCode typeCode = Convert.GetTypeCode(value);
            ulong result;

            switch(typeCode)
            {
                case TypeCode.SByte:
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                    result = (UInt64)Convert.ToInt64(value, CultureInfo.InvariantCulture);
                    break;

                case TypeCode.Byte:
                case TypeCode.UInt16:
                case TypeCode.UInt32:
                case TypeCode.UInt64:
                    result = Convert.ToUInt64(value, CultureInfo.InvariantCulture);
                    break;

                default:
                // All unsigned types will be directly cast
                    BCLDebug.Assert(false, "Invalid Object type in ToUInt64");
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
            }
            return result;
        }

Usage Example

Пример #1
0
        // Convert everything to ulong then perform a binary search.
        private static int BinarySearch(Array array, object value)
        {
            ulong[] ulArray = new ulong[array.Length];
            for (int i = 0; i < array.Length; ++i)
            {
                ulArray[i] = Enum.ToUInt64(array.GetValue(i) !);
            }

            ulong ulValue = Enum.ToUInt64(value);

            return(Array.BinarySearch(ulArray, ulValue));
        }
All Usage Examples Of System.Enum::ToUInt64