ArrayList是最老的容器了吧,C#1时代的,List<T>泛型容器是C#2之后的。那么请问,有没有什么情形,仍然推荐使用ArrayList而不是List<T>的? 效率问题?
解决方案 »
- 最近在用WPF做搜狐微薄开发 遇到 远程服务器返回错误: (500) 内部服务器错误。求高手解决..帮帮忙阿....
- Visual Studio 2005 IDE 支持Word文档的承载。怎么实现的啊??
- 在子表DataTable中添加一列,让该列的值为父表对应的字段有什么好办法(foreach子表怕效率不高)
- 帮我看看,或是顶一个快速排序法!
- C#单步调试问题,高手请进
- DataGrid怎样动态修改超级连接列?
- 哪位朋友介绍一下SQL SERVER 好的视频教程●●●
- c#多线程问题,关于更新richtextbox不能同步!!!
- 关于DropDownList, DataGrid.
- 求一段循环生成50个GUID的代码
- vs打包.net framework问题
- C#动态加载界面的问题
和 ArrayList用法上基本无差别具体性能有无差异,这个没测试过
胡扯。
List<T>在创建的时候的时间消耗比ArrayList要大?
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
List<object>[] a1 = new List<object>[10000000];
for (int i = 0; i < 10000000; i++)
{
a1[i] = new List<object>();
}
sw.Stop();
Console.WriteLine(sw.ElapsedTicks);
sw.Reset();
sw.Start();
ArrayList[] a2 = new ArrayList[10000000];
for (int i = 0; i < 10000000; i++)
{
a2[i] = new ArrayList();
}
sw.Stop();
Console.WriteLine(sw.ElapsedTicks);
}
}
}90071119
91062186
Press any key to continue . . .运行了10多次,互有胜负。
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000000; i++)
{
var x = new List<object>();
for (int j = 0; j < 100; j++)
{
x.Add(j);
}
}
sw.Stop();
Console.WriteLine(sw.ElapsedTicks);
sw.Reset();
sw.Start();
for (int i = 0; i < 1000000; i++)
{
var y = new ArrayList();
for (int j = 0; j < 100; j++)
{
y.Add(j);
}
}
sw.Stop();
Console.WriteLine(sw.ElapsedTicks);
}
}
}
测试100个元素的插入,算小数据量了吧。同样在一个数量级上。94096078
107058149
Press any key to continue . . .
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000000; i++)
{
var x = new List<object>();
for (int j = 0; j < 10; j++)
{
x.Add(j);
}
}
sw.Stop();
Console.WriteLine(sw.ElapsedTicks);
sw.Reset();
sw.Start();
for (int i = 0; i < 1000000; i++)
{
var y = new ArrayList();
for (int j = 0; j < 10; j++)
{
y.Add(j);
}
}
sw.Stop();
Console.WriteLine(sw.ElapsedTicks);
}
}
}17402617
17170626
Press any key to continue . . .