Slide 9.12: Arrays
Slide 10.1: Programming Exercise IV: A simple online bookstore
Home

Arrays (Cont.)


An Example (Cont.)

The following program is the implementation of the example:

01using System;
02using System.Windows.Forms;
03 
04namespace WindowsFormsApp2 {
05  public partial class Array : Form {
06    public Array( ) { InitializeComponent( ); }
07 
08    private void addName( ) {
09      string[ ] studentName = new string[5];
10      for ( int i = 0; i < 5; i++ ) {
11         studentName[i] = Microsoft.VisualBasic.Interaction.InputBox(
12           "Enter the student name:" );
13         nameList.Items.Add( studentName[i] );
14      }
15    }
16    private void Start_Click( object sender, EventArgs e ) {
17      nameList.Items.Clear( );
18      addName( );
19    }
20    private void Exit_Click( object sender, EventArgs e ) {
21      Application.Exit( );
22    }
23  }
24}
In order to make the VB InputBox Microsoft.VisualBasic.Interaction.InputBox work for C#, add the Microsoft.VisualBasic by using the Reference Manager:
  1. Right click the project WindowsFormsApp2 in the Visual Studio,
  2. Select the option Add, and
  3. Select the option Reference....