forked from bizzlemip/BiggerLobby
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Helper.cs
34 lines (31 loc) · 945 Bytes
/
Helper.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
using System.Collections.Generic;
using System.Linq;
namespace BiggerLobby
{
public static class Helper
{
public static T[] ResizeArray<T>(T[] oldArray, int newSize) {
if (oldArray.Length >= newSize)
{
return oldArray;
}
var newArray = new T[newSize];
oldArray.CopyTo(newArray, 0);
return newArray;
}
public static void ResizeList<T>(this List<T> list, int size, T element = default(T))
{
int count = list.Count;
if (size < count)
{
list.RemoveRange(size, count - size);
}
else if (size > count)
{
if (size > list.Capacity) // Optimization
list.Capacity = size;
list.AddRange(Enumerable.Repeat(element, size - count));
}
}
}
}