/// <summary> /// Finds the first object in a list where a certain user defined equality is true /// </summary> /// <param name="data">Dataset to search.</param> /// <param name="what">What to lookfor.</param> /// <param name="equality">How to determine if the object in the list is equivilent to the item we are searching for.</param> /// <returns>Index of the value in the list, -1 if item was not found.</returns> public static int search(IList data, object what, equalDelegate equality) { int i; for (i = 0; i < data.Count; i++) { if (equality(what, data[i])) { return(i); } } return(-1); }
/// <summary> /// akin to "select * from data where equality(what, data)" /// </summary> /// <param name="data">Dataset to search.</param> /// <param name="what">What to lookfor.</param> /// <param name="equality">How to determine if the object in the list is equivilent to the item we are searching for.</param> /// <returns>A new dataset representing the information meeting the specified criteria.</returns> public static object[] allFormListWhere(IList data, object what, equalDelegate equality) { ArrayList items = new ArrayList(); int i; for (i = 0; i < data.Count; i++) { if (equality(what, data[i])) { items.Add(data[i]); } } return(items.ToArray()); }