using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace demo5
{
class Program
{
static void Main(string[] args)
{
ArrayList test = new ArrayList();
//test.Add(new TestArrary("demo", 20));
//test.Add(new TestArrary("demo1", 21));
int[] a = new int[3] { 1,2,3};//这个类实现了icollection接口
test.Add("a");
test.Add("b");
test.Add("c");
string [] string_ary=new string[3];
test.CopyTo(string_ary);
Console.WriteLine("复制成功");
foreach (string string_var in string_ary)
{
Console.WriteLine(string_var);
}
string [] string_ary1=new string[3];
test.CopyTo(string_ary1,0);//从目标数组的index开始复制
Console.WriteLine("复制成功");
string [] string_ary2=new string[6];
test.CopyTo(0,string_ary2,2,3);//
Console.WriteLine("复制成功");
foreach(string string_ary2_var in string_ary2)
{
Console.WriteLine(string_ary2_var);
}
// test.AddRange(a);
//foreach(TestArrary b in test)
//{
// Console.WriteLine(b.name.ToString());
//}
//Console.WriteLine("第一个元素为:" + test[0]);
//test.Clear();
//Console.WriteLine("里面的数量为:"+test.Count+"个元素");
if (test.Contains(new TestArrary("demo", 20)))//因这两个对象不是同一个对象了
{
Console.WriteLine("存在");
}
else
{
Console.WriteLine("不存在");
}
Console.WriteLine("===================");
foreach(string string_GetRange in test.GetRange(0,2))
{
Console.WriteLine(string_GetRange);
}
Console.WriteLine("b出现在索引:"+test.IndexOf("b"));//第一次出现的索引
if (test.IndexOf("b", 2) == -1)//从指定的位置开始查找直到元素的末尾,返回第一次出现的索引
{
Console.WriteLine("找不到该元素");
}
else
{
Console.WriteLine("该元素的索引是:"+test.IndexOf("b",2));
}
Console.WriteLine("=====================");
if (test.IndexOf("b", 0, 3) == -1)//从指定的位置索引指定数量的元素的第一次出现的索引
{
Console.WriteLine("找不到该元素");
}
else
{
Console.WriteLine("该元素的索引为:"+test.IndexOf("b",0,3));
}
Console.WriteLine("=======================================");
test.Insert(0,"chaiyesong");
Console.WriteLine("插入成功");
test.Reverse();
Console.WriteLine("开始反转");
foreach(string string_insert in test)
{
Console.WriteLine(string_insert);
}
Console.WriteLine("开始顺转");
test.Sort();
foreach (string string_insert in test)
{
Console.WriteLine(string_insert);
}
Console.ReadKey();
}
}
}
|