Top experts in the last 24hrs section of the Code project,
Codeproject article about extension methods of IEnumerable in C# in
I posted another article about extension methods of IEnumerable in C# in the Codeproject. It could be found in here
Few extension methods of IEnumerable
Following code shows few extension methods of IEnumerable<string>,
public static class EnumberableExtensions
{ public static IEnumerable<string> IfMatchWith(this IEnumerable<string> myList, string itemToMatch) { foreach (var item in myList.Where(item => item == itemToMatch)) yield return item; } public static IEnumerable<string> IfNotMatchWith(this IEnumerable<string> myList, string itemToMatch) { foreach (var item in myList.Where(item => item != itemToMatch)) yield return item; } public static IEnumerable<string> IgnoreNullOrEmptyOrSpace(this IEnumerable<string> myList) { foreach (var item in myList.Where(item => !string.IsNullOrEmpty(item) && item != " ")) yield return item; } public static IEnumerable<string> MakeAllUpper(this IEnumerable<string> myList) { foreach (var item in myList) yield return item.ToUpper(); } public static IEnumerable<string> MakeAllLower(this IEnumerable<string> myList) { foreach (var item in myList) yield return item.ToLower(); } public static IEnumerable<T> MakeAllDefault<T>(this IEnumerable<T> myList) { foreach (var item in myList) yield return default(T); } public static IEnumerable<string> IfMatchWithPattern(this IEnumerable<string> myList, string pattern) { foreach (var item in myList.Where(item => Regex.IsMatch(item, pattern))) yield return item; } public static IEnumerable<string> IfLengthEquals(this IEnumerable<string> myList, int itemLength) { foreach (var item in myList.Where(item => item.Length == itemLength)) yield return item; } public static IEnumerable<string> IfLengthInRange(this IEnumerable<string> myList, int startOfRange, int endOfRange) { foreach (var item in myList.Where(item => item.Length >= startOfRange && item.Length <= endOfRange)) yield return item; } }
Subscribe to:
Posts (Atom)