-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arrays.cs
41 lines (37 loc) · 1.13 KB
/
Arrays.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//---------------------------------------------------------------------------------------------------------
// Copyright © 2007 - 2021 Tangible Software Solutions, Inc.
// This class can be used by anyone provided that the copyright notice remains intact.
//
// This class is used to replace some calls to java.util.Arrays methods with the C# equivalent.
//---------------------------------------------------------------------------------------------------------
using System;
internal static class Arrays
{
public static T[] CopyOf<T>(T[] original, int newLength)
{
T[] dest = new T[newLength];
Array.Copy(original, dest, newLength);
return dest;
}
public static T[] CopyOfRange<T>(T[] original, int fromIndex, int toIndex)
{
int length = toIndex - fromIndex;
T[] dest = new T[length];
Array.Copy(original, fromIndex, dest, 0, length);
return dest;
}
public static void Fill<T>(T[] array, T value)
{
for (int i = 0; i < array.Length; i++)
{
array[i] = value;
}
}
public static void Fill<T>(T[] array, int fromIndex, int toIndex, T value)
{
for (int i = fromIndex; i < toIndex; i++)
{
array[i] = value;
}
}
}