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是类,虽然叫数组但和数组不一样。