using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 面向对象集合
{
class Program
{
static void Main(string[] args)
{
//创建一个集合对象
ArrayList list = new ArrayList();
//集合:很多数据的一个集合
//数组:长度不可变,类型单一
//集合的优点:长度可以任意改变,类型也不固定。
list.Add();
list.Add(3.14);
list.Add(true);
list.Add("张三");
list.Add('男');
list.Add(5000m);
list.Add(new int[] { , , , , , , , , });
person p = new person();
list.Add(p);
list.Add(list); //没有判断的情况下输出的是集合ArrayList的命名空间
for (int i = ; i < list.Count; i++)
{
// Console.WriteLine(list[i]);
if (list[i] is person)
{
((person)list[i]).Sayhello();
}
else if (list[i] is int[])
{
for (int j = ; j < ((int[])list[i]).Length; j++)
{
Console.WriteLine(((int[])list[i])[j]);
}
}
else
{
Console.WriteLine(list[i]);//未判断
} }
Console.ReadLine();
}
public class person
{
public void Sayhello()
{
Console.WriteLine("我是人类");
}
}
}
}
list.AddRange(new int[] { , , , , , , , , }); //添加集合用AddRange
for (int i = ; i < list.Count; i++)
{
Console.WriteLine( list[i]);
}
Console.ReadLine();