BetterMembership.Extensions.NameValueCollectionExtension.GetInteger C# (CSharp) Method

GetInteger() public static method

public static GetInteger ( this collection, string key, int defaultValue ) : int
collection this
key string
defaultValue int
return int
        public static int GetInteger(this NameValueCollection collection, string key, int defaultValue = 0)
        {
            Condition.Requires(key, "key").IsNotNullOrWhiteSpace();

            if (collection == null)
            {
                return defaultValue;
            }

            var value = collection.GetString(key);
            if (string.IsNullOrWhiteSpace(value))
            {
                return defaultValue;
            }

            int returnValue;
            return int.TryParse(value, out returnValue) ? returnValue : defaultValue;
        }