如果textBoxNumber.Text的值大于10000的时候,下面两个函数执行的性能会差很多,所有在处理比较大的数据的时候尽量使用Dictionary.
private void button1_Click(object sender, EventArgs e)
{DateTime dt = System.DateTime.Now;
int num = Convert.ToInt32(textBoxNumber.Text);
IList<int> lst = new List<int>();
for (int i = 0; i < num; i++)
{
if (!lst.Contains(i))
{
lst.Add(i);
}
}
textBox1.Text = (DateTime.Now - dt).ToString();
}
private void button2_Click(object sender, EventArgs e)
{
DateTime dt=System.DateTime.Now;
int num = Convert.ToInt32(textBoxNumber.Text);
IDictionary<int, object> dict = new Dictionary<int, object>();
for (int i = 0; i < num; i++)
{
if (!dict.ContainsKey(i))
{
dict.Add(i,null);
}
}
textBox2.Text = (DateTime.Now - dt).ToString();
}