System.Number.TryParseSingle C# (CSharp) Method

TryParseSingle() static private method

static private TryParseSingle ( String value, NumberStyles options, NumberFormatInfo numfmt, Single &result ) : Boolean
value String
options NumberStyles
numfmt NumberFormatInfo
result Single
return Boolean
        internal unsafe static Boolean TryParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt, out Single result) {
            Byte * numberBufferBytes = stackalloc Byte[NumberBuffer.NumberBufferBytes];
            NumberBuffer number = new NumberBuffer(numberBufferBytes);
            result = 0;
            Double d = 0;

            if (!TryStringToNumber(value, options, ref number, numfmt, false)) {
                return false;
            }
            if (!NumberBufferToDouble(number.PackForNative(), ref d)) {
                return false;
            }
            Single castSingle = (Single)d;
            if (Single.IsInfinity(castSingle)) {
                return false;
            }

            result = castSingle;
            return true;
        }

Usage Example

示例#1
0
        private static Boolean TryParse(String s, NumberStyles style, NumberFormatInfo info, out Single result)
        {
            if (s == null)
            {
                result = 0;
                return(false);
            }
            bool success = Number.TryParseSingle(s, style, info, out result);

            if (!success)
            {
                String sTrim = s.Trim();
                if (sTrim.Equals(info.PositiveInfinitySymbol))
                {
                    result = PositiveInfinity;
                }
                else if (sTrim.Equals(info.NegativeInfinitySymbol))
                {
                    result = NegativeInfinity;
                }
                else if (sTrim.Equals(info.NaNSymbol))
                {
                    result = NaN;
                }
                else
                {
                    return(false); // We really failed
                }
            }
            return(true);
        }
All Usage Examples Of System.Number::TryParseSingle