日期:2014-05-17  浏览次数:20900 次

ArrayList可以添加任何类型的对象?
下面居然没错,ArrayList可以添加任何类型的对象?还是说没错只是个巧合
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Collections;

namespace Csharp
{
    class People
    {
        public void DoSomething()
        {
            Console.WriteLine("People::DoSomething()");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList array = new ArrayList();
            array.Add(new People());
            array.Add(new People());
            array.Add(new int());
            Console.WriteLine(array.Count);
            Console.ReadKey();
        }
    }
}

------解决方案--------------------

ArrayList:
public virtual int Add (
Object value
)

------解决方案--------------------
ArrayList为非泛型集合
可以添加任何类型对象
------解决方案--------------------
ArrayList中元素的类型是object,所以可以放任何类型的对象。
------解决方案--------------------
不是巧合,就是这样的。
------解决方案--------------------
Array是类,虽然叫数组但和数组不一样。