Get As Float - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get As Float

Demo Code


using System.Xml.Linq;
using System;/*w w w . j av  a 2  s  . c o  m*/

public class Main{
        #endregion

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

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

            return ret;
        }
}

Related Tutorials