using System; using System.Collections.Generic; namespace SPSolutions { public class IntegerUtil { public static int GetFirstValidInteger(object[] potentialIntegers, int defaultValue) { List list = new List(); for (int i = 0; i < potentialIntegers.Length; i++) { object obj = potentialIntegers[i]; if (obj != null) { if (obj is int) { return (int)obj; } list.Add(obj.ToString()); } } return IntegerUtil.GetFirstValidInteger(list.ToArray(), defaultValue); } public static int GetFirstValidInteger(string[] potentialIntegers, int defaultValue) { for (int i = 0; i < potentialIntegers.Length; i++) { string text = potentialIntegers[i]; int result; if (!string.IsNullOrEmpty(text) && int.TryParse(text, out result)) { return result; } } return defaultValue; } } }