[Modify] Throw exception
This commit is contained in:
parent
26dadfa133
commit
ef2dec992c
@ -1584,15 +1584,25 @@ namespace WebSocketSharp
|
|||||||
/// </typeparam>
|
/// </typeparam>
|
||||||
public static T[] SubArray<T> (this T[] array, int startIndex, int length)
|
public static T[] SubArray<T> (this T[] array, int startIndex, int length)
|
||||||
{
|
{
|
||||||
int len;
|
if (array == null)
|
||||||
if (array == null || (len = array.Length) == 0)
|
throw new ArgumentNullException ("array");
|
||||||
return new T[0];
|
|
||||||
|
|
||||||
if (startIndex < 0 || length <= 0 || startIndex + length > len)
|
var len = array.Length;
|
||||||
return new T[0];
|
if (len == 0) {
|
||||||
|
if (startIndex != 0)
|
||||||
|
throw new ArgumentOutOfRangeException ("startIndex");
|
||||||
|
|
||||||
|
if (length != 0)
|
||||||
|
throw new ArgumentOutOfRangeException ("length");
|
||||||
|
|
||||||
if (startIndex == 0 && length == len)
|
|
||||||
return array;
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startIndex < 0 || startIndex > len - 1)
|
||||||
|
throw new ArgumentOutOfRangeException ("startIndex");
|
||||||
|
|
||||||
|
if (length < 0 || length > len - startIndex)
|
||||||
|
throw new ArgumentOutOfRangeException ("length");
|
||||||
|
|
||||||
var subArray = new T[length];
|
var subArray = new T[length];
|
||||||
Array.Copy (array, startIndex, subArray, 0, length);
|
Array.Copy (array, startIndex, subArray, 0, length);
|
||||||
|
Loading…
Reference in New Issue
Block a user