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:

 using System;
 using System.Windows.Forms;

 namespace WindowsFormsApp2 {
   public partial class Array : Form {
     public Array( ) { InitializeComponent( ); }

     private void addName( ) {
       string[ ] studentName = new string[5];
       for ( int i = 0; i < 5; i++ ) {
          studentName[i] = Microsoft.VisualBasic.Interaction.InputBox( 
            "Enter the student name:" );
          nameList.Items.Add( studentName[i] );
       }
     }
     private void Start_Click( object sender, EventArgs e ) {
       nameList.Items.Clear( );
       addName( );
     }
     private void Exit_Click( object sender, EventArgs e ) {
       Application.Exit( );
     }
   }
 }
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....