0

I hvae created a code in C# but I had this error :

Error 1 Using the generic type 'System.Collections.Generic.List' requires '1' type arguments C:\Users\Abdelhakim\Desktop\Wind Applic C#\Exercice4\Exercice4\Form1.cs 9 34 Exercice4

and this is the code I wrote :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic.List;
namespace Exercice4
{
    public partial class Form1 : Form
    {
        List<string> ls = new List<string>();
        string p;

        public Form1()
        {

            InitializeComponent();
        }
        private void label2_Click(object sender, EventArgs e)
        {
        }
        private void r1_CheckedChanged(object sender, EventArgs e)
        {
            p = "+";
            l3.Text = (Convert.ToDouble(t1.Text) + Convert.ToDouble(t2.Text)).ToString();
        }
        private void r2_CheckedChanged(object sender, EventArgs e)
        {
            p = "-";
            l3.Text = (Convert.ToDouble(t1.Text) - Convert.ToDouble(t2.Text)).ToString();
        }
        private void r3_CheckedChanged(object sender, EventArgs e)
        {
            p = "*";
            l3.Text = (Convert.ToDouble(t1.Text) * Convert.ToDouble(t2.Text)).ToString();
        }
        private void r4_CheckedChanged(object sender, EventArgs e)
        {
            p = "/";
            if (Convert.ToDouble(t2.Text) == 0)
                l3.Text = "Erreur";
            else
                l3.Text = (Convert.ToDouble(t1.Text) / Convert.ToDouble(t2.Text)).ToString();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int i;
            for (i = 0; i < ls.Count; i++)
                ls.Items.Add(ls[i]);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            ls.Add(t1.Text + p + t2.Text + " =" + l3.Text);
        }
    }
}
4

1 回答 1

2

using指令只能与命名空间一起使用,而不是单个类型。

更改此行

using System.Collections.Generic.List;

using System.Collections.Generic;

要解决您的下一个问题,您需要更改此行:

ls.Items.Add(ls[i]);

ls.Add(ls[i]);

这应该允许您的代码编译,但是,这将导致无限循环,因为您不断地将相同的项目永远添加回您的列表中。您需要重新考虑您要在该button1_Click方法中执行的操作。

于 2013-03-17T17:09:58.447 回答