Reputation: 233
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);
}
}
}
Upvotes: 0
Views: 5479
Reputation: 149108
The using
directive can only be used with namespaces, not individual types.
Change this line
using System.Collections.Generic.List;
To
using System.Collections.Generic;
To fix your next issue, you will need to change this line:
ls.Items.Add(ls[i]);
To
ls.Add(ls[i]);
That should allow your code to compile, however, this will result in an infinite loop as you constantly add the same items back into your list forever. You need to rethink what you're trying to do in the button1_Click
method.
Upvotes: 2