-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arrays.cs
65 lines (61 loc) · 1.88 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace EssentialMechanics.Logic
{
public class Arrays
{
public static List<T> ArrayToList<T>(T[] array)
{
List<T> list = new List<T>();
foreach (T t in array)
list.Add(t);
return list;
}
public static T[] ListToArray<T>(List<T> list)
{
T[] t = new T[list.Count];
for (int i = 0; i < list.Count; i++)
t[i] = list[i];
return t;
}
public static List<Y> DictionaryToList<T, Y>(Dictionary<T, Y> dictionary)
{
List<Y> list = new List<Y>();
foreach (Y y in dictionary.Values)
list.Add(y);
return list;
}
public static Dictionary<T, Y> ListToDictionary<T, Y>(T[] key,List<Y> list)
{
Dictionary<T, Y> dictionary = new Dictionary<T, Y>();
for (int i = 0; i < list.Count; i++)
if(i<key.Length)
dictionary.Add(key[i], list[i]);
return dictionary;
}
public static Dictionary<int, T> ListToDictionary<T>(List<T> list)
{
Dictionary<int, T> dictionary = new Dictionary<int, T>();
for (int i =0;i<list.Count;i++)
dictionary.Add(i, list[i]);
return dictionary;
}
public static List<T> invertList<T>(List<T> list)
{
List<T> invertList = new List<T>();
for(int i = list.Count-1; i > 0; i--)
{
invertList.Add(list[i]);
}
return invertList;
}
public static List<T> addList<T>(List<T> listA, List<T> listB)
{
foreach (T t in listB) {
listA.Add(t);
}
return listA;
}
}
}