首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

ArrayList可以平添任何类型的对象

2013-01-17 
ArrayList可以添加任何类型的对象?下面居然没错,ArrayList可以添加任何类型的对象?还是说没错只是个巧合us

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

热点排行