This extension method replaces an item in a collection that implements the IList interface.
////// This extension method replaces an item in a collection that implements the IList interface. /// ///The type of the field that we are manipulating /// The input list /// The position of the old item /// The item we are goint to put in it's place ///True in case of a replace, false if failed public static bool Replace(this IList thisList, int position, T item) { if (position > thisList.Count - 1) return false; // only process if inside the range of this list thisList.RemoveAt(position); // remove the old item thisList.Insert(position, item); // insert the new item at its position return true; // return success }
10:21 AM
Rajesh Rolen
0 comments:
Post a Comment