Get As Short - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get As Short

Demo Code


using System.Xml.Linq;
using System;// w  ww . jav a  2 s .  c  o m

public class Main{
        #endregion

        #region GetAsShort Method
        public static short GetAsShort(this XAttribute attr)
        {
            short ret = 0;
            short value = 0;

            if (attr != null && !string.IsNullOrEmpty(attr.Value))
            {
                if (short.TryParse(attr.Value, out value))
                    ret = value;
            }

            return ret;
        }
}

Related Tutorials