Extension methods missing from System.Array in the .NET Framework 3.5 (Beta 1)

UPDATE: Extension methods

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>