- array
int[] array1={10,20,30};
int[,] array2={{10,20,30}, {10,20,30}};
int[,,] array3={{{10,20,30}, {10,20,30}}, {{10,20,30}, {10,20,30}}};
int[] array_example=new int[10];
int[] temp;
void Start()
{
temp=new int[array1.Length];
print(temp.Length);
print(array3[1,1,2]);
}
>>>
3
30
- ArrayList
Any type can be put in.
arrayList.Add(1);
arrayList.Add("abc");
arrayList.Add(2);
// arrayList.Remove("abc");
// arrayList.RemoveAt(0);
// arrayList.RemoveRange(0,1); //Remove the values from index x to y
// arrayList.Clear(); //remove all the array
for (int i = 0; i < arrayList.Count; i++)
{
print(arrayList[i]);
}
>>>
abc
2
- List
Must declare the type to put in.
List<int> temp=new List<int>();
- Hashtable
Similar as dictionary but any type can be put in.
Hashtable temp=new Hashtable();
void Start()
{
temp.Add(1, "a");
temp.Add(2, "b");
print(temp[1]);
}
>>>
a
- Dictionary
Must declare the type to put in.
Dictionary<string,int> temp=new Dictionary<string, int>();
- Queue
First In First Out.
In used by Enqueue, Out used by Dequeue.
Queue<int> temp=new Queue<int>();
void Start()
{
temp.Enqueue(1);
temp.Enqueue(2);
if(temp.Count!=0)
print(temp.Dequeue());
if(temp.Count!=0)
print(temp.Dequeue());
}
>>>
1
2
- Stack
Last In First Out.
In used by Push, Out used by Pop.
Stack<int> temp=new Stack<int>();
void Start()
{
temp.Push(1);
temp.Push(2);
// if(temp.Count!=0)
// print(temp.Dequeue());
if(temp.Count!=0)
print(temp.Pop());
print(temp.Pop());
}
>>>
2
1
'C#' 카테고리의 다른 글
inheritance : class VS interface (0) | 2023.02.24 |
---|---|
namespace, struct, enum, property, indexer (0) | 2023.02.23 |
private VS public VS protected VS abstract VS virtual (0) | 2023.02.21 |
delegate VS event (0) | 2023.02.21 |
Parse, void, private, static, operation, conditional, Iteration, foreach (0) | 2023.02.10 |