Filling ListBox using the for loop

Now we'll take our loop and fill the box. How can we accomplish this? Well, take a look.

If you had ListBox1.Items.Clear()earlier, you very likely have a method called Add here:

ListBox1.Items.Add(i);

Notice the list of methods that you can run that pops up as you type (see Figure 3.4.6). You can clear away the items in the list or you can add to them. You can put an item inside the list, then put in i and close with a semicolon:

Figure 3.4.6: Popup of the list of methods that you can run

Wait! There's an error message. If you hover your mouse over i, the message appears, as shown in the following screenshot: ...

Get Beginning C# 7 Hands-On – The Core Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.