Specified object to convert the SByte. - CSharp System

CSharp examples for System:Converter

Description

Specified object to convert the SByte.

Demo Code


using System.Xml.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;/*ww  w.  j  a  v  a2 s. co m*/
using System.Globalization;
using System.Collections.Generic;
using System;

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

            if (SByte.TryParse(ToStringOrEmpty(value), numberStyle, formatProvider, out x))
            {
                return x;
            }
            return null;
        }
        /// <summary>
        /// Specified object to convert the SByte.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static SByte? ToSByte(Object value)
        {
            return ToSByte(value, DefaultNumberStyle, null);
        }
        /// <summary>
        /// Specified object to convert the SByte.

        /// </summary>
        /// <param name="value"></param>
        /// <param name="defaultValue"></param>
        /// <param name="numberStyle"></param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public static SByte ToSByte(Object value, SByte defaultValue, NumberStyles numberStyle, IFormatProvider formatProvider)
        {
            return ToSByte(value, numberStyle, formatProvider) ?? defaultValue;
        }
        /// <summary>
        /// Specified object to convert the SByte.

        /// </summary>
        /// <param name="value"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static SByte ToSByte(Object value, SByte defaultValue)
        {
            return ToSByte(value) ?? defaultValue;
        }
}

Related Tutorials