Specified object to convert the UInt 16. - CSharp System

CSharp examples for System:Converter

Description

Specified object to convert the UInt 16.

Demo Code


using System.Xml.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;//from  w w  w . ja v a  2  s  .c o  m
using System.Globalization;
using System.Collections.Generic;
using System;

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

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

Related Tutorials