by Paulo Morgado via Paulo Morgado : C# on 5/13/2007 6:51:48 PM
Extension methods are a feature of the new C# language specification (also available in Visual Basic [^] [^]):
This new feature should be used in existing classes like the Array class by making the folowing methods extension methods:
public static System.Collections.ObjectModel.ReadOnlyCollection<T> AsReadOnly<T>(this T[] array);
public static int BinarySearch<T>(this T[] array, T value);
public static int BinarySearch(this Array array, object value);
public static int BinarySearch<T>(this T[] array, T value, System.IComparer<T> comparer);
public static int BinarySearch<T>(this T[] array, int index, int length, T value);
public static int BinarySearch<T>(this T[] array, int index, int length, T value, System.IComparer<T> comparer);
public static void ConstrainedCopy<T>(this T[] sourceArray, int sourceIndex, T[] destinationArray, int destinationIndex, int length);
public static TOutput[] ConvertAll<TInput, TOutput>(this TInput[] array, System.Converter<TInput, TOutput> converter);
public static void Copy<T>(this T[] sourceArray, T[] destinationArray, int length);
public static void Copy<T>(this T[] sourceArray, T[] destinationArray, long length);
public static void Copy<T>(this T[] sourceArray, int sourceIndex, T[] destinationArray, int destinationIndex, int length);
public static void Copy<T>(this T[] sourceArray, long sourceIndex, T[] destinationArray, long destinationIndex, long length);
public static bool Exists<T>(this T[] array, System.Predicate<T> match);
public static T Find<T>(this T[] array, System.Predicate<T> match);
public static T[] FindAll<T>(this T[] array, System.Predicate<T> match);
public static int FindIndex<T>(this T[] array, System.Predicate<T> match);
public static int FindIndex<T>(this T[] array, int startIndex, System.Predicate<T> match);
public static int FindIndex<T>(this T[] array, int startIndex, int count, System.Predicate<T> match);
public static T FindLast<T>(this T[] array, System.Predicate<T> match);
public static int FindLastIndex<T>(this T[] array, System.Predicate<T> match);
public static int FindLastIndex<T>(this T[] array, int startIndex, System.Predicate<T> match);
public static int FindLastIndex<T>(this T[] array, int startIndex, int count, System.Predicate<T> match);
public static void ForEach<T>(this T[] array, Action<T> action);
public static int IndexOf<T>(this T[] array, T value);
public static int IndexOf<T>(this T[] array, T value, int startIndex);
public static int IndexOf<T>(this T[] array, T value, int startIndex, int count);
public static int LastIndexOf<T>(this T[] array, T value);
public static int LastIndexOf<T>(this T[] array, T value, int startIndex);
public static int LastIndexOf<T>(this T[] array, T value, int startIndex, int count);
public static void Resize<T>(this ref T[] array, int newSize);
public static void Sort<T>(this T[] array);
public static void Sort<T>(this T[] array, System.IComparer<T> comparer);
public static void Sort<T>(this T[] array, System.Comparison<T> comparison);
public static void Sort<TKey, TValue>(this TKey[] keys, TValue[] items);
public static void Sort<T>(this T[] array, int index, int length);
public static void Sort<TKey, TValue>(this TKey[] keys, TValue[] items, System.IComparer<TKey> comparer);
public static void Sort<T>(this T[] array, int index, int length, System.IComparer<T> comparer);
public static void Sort<TKey, TValue>(this TKey[] keys, TValue[] items, int index, int length);
public static void Sort<TKey, TValue>(this TKey[] keys, TValue[] items, int index, int length, System.IComparer<TKey> comparer);
public static bool TrueForAll<T>(this T[] array, System.Predicate<T> match);
This would allow us to write code like this:
if (someArray.IndefOf(someValue))
{
//...
}
If you would like to see this in the next release of the .NET framework, vote on this suggestion.
Original Post: Extension methods missing from System.Array in the .NET Framework 3.5 (Beta 1)
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.