I want to write some extension methods for arrays. I'm not quite sure how to approach this.
Suppose I have an array:
byte[] myArray = new byte[24];
// populate byte array here
I want something like
bool areArraysEqual = myArray.CompareTo(anotherArray);
or
byte[] subArray = myArray.Slice(5,3); // offset 5, 3 items
I want to enforce typing, so that if I use the Slice command I can't assign a byte array's Slice to a string array, for example.
I have code written for these methods, with the following method signature:
public static T[] Slice<T>(T[] inArray, int startOffset, int Length)
and
public static bool Compare<T>(T[] a1, T[] a2)
How can I convert these to extension methods that could be called on an array rather than passing references to arrays into the static methods?
fm

1 answers
You can do it like this (method implementations just for illustration, not necessarily optimal):
answered 2 years ago by:
17279