Specified object to convert the Single. - CSharp System

CSharp examples for System:Converter

Description

Specified object to convert the Single.

Demo Code


using System.Xml.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;//from   w  ww . j  ava2  s.  c o m
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        /// <summary>
        /// Specified object to convert the Single.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="numberStyle"></param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public static Single? ToSingle(Object value, NumberStyles numberStyle, IFormatProvider formatProvider)
        {
            Single x;

            if (value is float)
            { return (Single)value; }
            if (Single.TryParse(ToStringOrEmpty(value), numberStyle, formatProvider, out x))
            {
                return x;
            }
            return null;
        }
        /// <summary>
        /// Specified object to convert the Single.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Single? ToSingle(Object value)
        {
            return ToSingle(value, DefaultDoubleNumberStyle, null);
        }
        /// <summary>
        /// Specified object to convert the Single.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="defaultValue"></param>
        /// <param name="numberStyle"></param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public static Single ToSingle(Object value, Single defaultValue, NumberStyles numberStyle, IFormatProvider formatProvider)
        {
            return ToSingle(value, numberStyle, formatProvider) ?? defaultValue;
        }
        /// <summary>
        /// Specified object to convert the Single.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static Single ToSingle(Object value, Single defaultValue)
        {
            return ToSingle(value) ?? defaultValue;
        }
}

Related Tutorials