Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# index not in context

Tags:

c#

I am can't figure out how to put the index [i] in the context when I try to write in to the listbox1. The code I got so far is:

    private void button1_Click(object sender, EventArgs e)
    {            
        StreamWriter Info = File.AppendText("Contacts.txt");

        for (int i = 0; i < listBox1.Items.Count; i++);
            Info.WriteLine(listBox1.Items[i]);
        Info.Close();
    }

I am trying to make a Windows Form application that accepts names and email addresses and places them in a list box. Can anyone help me out on what I am missing here?

like image 955
user2514327 Avatar asked Feb 01 '26 21:02

user2514327


1 Answers

The semicolon in this line for (int i = 0; i < listBox1.Items.Count; i++); may cause an error. Delete it and then try again.

like image 169
Misa Lazovic Avatar answered Feb 03 '26 23:02

Misa Lazovic