Paulo Morgado

.NET Development & Architecture

This Blog

Syndication

Search

Tags

News

Unit Test Today! Get Typemock Isolator!

Projects

Books

 

Visitors

Visitor Locations

Community

Email Notifications

Archives

Profile

Disclaimer

The opinions and viewpoints expressed in this site are mine and do not necessarily reflect those of Microsoft, my employer or any community that I belong to. Any code or opinions are offered as is. Products or services mentioned are purchased by me, made available to me by my employer or the manufacturer/vendor which doesn't influence my opinion in any way.

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.

Published Sun, May 13 2007 19:51 by Paulo Morgado

Comments

# UPDATE: Extension methods@ Monday, May 14, 2007 5:34 PM

Looks like I was way wrong in here and here . I had thought that from the top of my head because I tried

Paulo Morgado

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: