public static GetInteger ( this collection, string key, int defaultValue ) : int | ||
collection | this | |
key | string | |
defaultValue | int | |
Résultat | 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;
}