1
2
|
int size = 5;
int [] test = new int [size];
|
1
2
3
4
5
6
7
|
string [] test2 = new string [3];
//赋值
test2[0] = "chen" ;
test2[1] = "j" ;
test2[2] = "d" ;
//修改
test2[0] = "chenjd" ;
|
01
02
03
04
05
06
07
08
09
10
11
|
ArrayList test3 = new ArrayList();
//新增数据
test3.Add( "chen" );
test3.Add( "j" );
test3.Add( "d" );
test3.Add( "is" );
test3.Add(25);
//修改数据
test3[4] = 26;
//删除数据
test3.RemoveAt(4);
|
1
2
3
4
5
6
7
|
//装箱,将String类型的值FanyoyChenjd赋值给对象。
String info = ”FanyoyChenjd”;
object obj=( object )info;
//拆箱,从Obj中提取值给info
object obj = "FanyoyChenjd" ;
String info = (String)obj;
|
01
02
03
04
05
06
07
08
09
10
11
|
List< string > test4 = new List< string >();
//新增数据
test4.Add(“Fanyoy”);
test4.Add(“Chenjd”);
//修改数据
test4[1] = “murongxiaopifu”;
//移除数据
test4.RemoveAt(0);
|
1
2
3
4
5
|
//EggArray类
//定义
public class EggArray class
{
}
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
|
//EggArray
private int capacity;
private int count;
private T[] items;
public int Count
{
get
{
return this .count;
}
}
public int Capacity
{
get
{
return this .capacity;
}
}
|
01
02
03
04
05
06
07
08
09
10
|
//EggArray的构造函数,默认容量为8
public EggArray() : this (8)
{
}
public EggArray( int capacity)
{
this .capacity = capacity;
this .items = new T[capacity];
}
|
1
2
3
4
5
6
7
8
9
|
List< int > test = new List< int >(){0,1,2,3,4,5,6,7,8,9};
int count = 0;
for ( int i = 0; i < test.Count; i++)
{
if (i == 1)
test.Remove(test[i]);
count++;
}
Debug.Log (count);
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
//当数组元素个[/size][/backcolor][/color][i][color=White][backcolor=DarkGreen][size=2]数不小于数组容量时,需要扩容,增长因子growthFactor为2
private void Resize()
{
int capacity = this .capacity * growthFactor;
if ( this .count > capacity)
{
this .count = capacity;
}
T[] destinationArray = new T[capacity];
Array.Copy( this .items, destinationArray, this .count);
this .items = destinationArray;
this .capacity = capacity;
}
private void Compact()
{
int num = 0;
for ( int i = 0; i < this .count; i++)
{
if ( this .items[i] == null )
{
num++;
}
else if (num > 0)
{
this .items[i - num] = this .items[i];
this .items[i] = null ;
}
}
this .count -= num;
}[i][i][i]
|