What is the result of the following code?
ArrayList intList = new ArrayList();
string strOutput = "";
intList.Add( 1 );
intList.Add( 3 );
intList.Add( 5 );
foreach ( int intListItems in intList )
{
strOutput += ( " " + intListItems.ToString() );
}
MessageBox.Show( strOutput, "Mystery",
MessageBoxButtons.OK, MessageBoxIcon.Information );
This code creates an ArrayList and adds to it the values 1, 3 and 5. The values are
then appended to each other (separated by spaces) using a foreach statement, and the result is displayed in a MessageBox. The complete code reads:
// MessageBox.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace MessageBoxes
{
///
/// Summary description for FrmMessageBox.
///
public class FrmMessageBox : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblOutputOut;
private System.Windows.Forms.Label lblOutput;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public FrmMessageBox()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent
// call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
// Windows Form Designer generated code
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run( new FrmMessageBox() );
}
private void FrmMessageBox_Load(
object sender, System.EventArgs e )
{
ArrayList intList = new ArrayList();
string strOutput = "";
intList.Add( 1 );
intList.Add( 3 );
intList.Add( 5 );
foreach ( int intListItems in intList )
{
strOutput += ( " " + intListItems.ToString() );
}
MessageBox.Show( strOutput, "Mystery",
MessageBoxButtons.OK, MessageBoxIcon.Information );
} // end method FrmMessageBox_Load
} // end class FrmMessageBox
}
You might also like to view...
What section for the main body of a form displays records and usually contains all the bound controls?
A. Form Header B. Page Header C. Page Footer D. Detail
Answer the following questions true (T) or false (F)
1. True/False: The bubble sort can be used to sort strings. 2. True/False: In a serial search, a variable called a flag is often used to indicate whether or not the search has been successful. A flag takes on one of two values. 3. True/False: The bubble sort algorithm sorts data either ascending or descending.