I just started to "work" with C#, so please be clement :D
I think this is a really easy task to the most of you, but I got a problem with this Method(I hope this is called "method"):
listBox1.Items.CopyTo(names, 1);
It don't pastes the content of the listbox into the array "names" and I don't know why.
The debugger just says that no values will be assigned to the field "names", it always has it's default value "zero".
(Thats not the exact message, I'm from germany so I got the german version of Visual C# ;) )
Here is the complete code:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string name;
int max, rand;
string[] names;
private void bttSub_Click(object sender, EventArgs e)
{
name = txtName.Text;
listBox1.Items.Add(name);
}
private void btt_Clear_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
private void bttRand_Click(object sender, EventArgs e)
{
max = listBox1.Items.Count + 1;
Random random = new Random();
rand = random.Next(1, max);
listBox1.Items.CopyTo(names, 1);
lblRand.Text = Convert.ToString(names[rand]);
}
}
}
Sry if there are any misspellings, I do my best to be understandable^^
Greets,
Forex


Sign In
Create Account

Back to top









