Specified object to convert the Byte. - CSharp System

CSharp examples for System:Converter

Description

Specified object to convert the Byte.

Demo Code


using System.Xml.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;/*from   ww  w  .  j  a  va 2  s .c  om*/
using System.Globalization;
using System.Collections.Generic;
using System;

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

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

Related Tutorials