Get As Integer - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get As Integer

Demo Code


using System.Xml.Linq;
using System;/*www. j ava2s.c  o  m*/

public class Main{
        #endregion

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

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

            return ret;
        }
}

Related Tutorials