Find the error(s) in the following code. The TwoDArrays method should create a two- dimensional array and initialize all its values to one.

What will be an ideal response?


The complete corrected code should read:



// Initialize.cs (Correct)



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;



namespace Initialize

{

///

/// Summary description for FrmInitialize.

///


public class FrmInitialize : System.Windows.Forms.Form

{

private System.Windows.Forms.Label lblArray;

private System.Windows.Forms.ListBox lstArray;

///

/// Required designer variable.

///


private System.ComponentModel.Container components = null;



public FrmInitialize()

{

//

// 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 FrmInitialize() );

}



// calls TwoDArrays and prints the resulting array

private void FrmInitialize_Load(

object sender, System.EventArgs e )

{

int[,] intTempArray = TwoDArrays();

int intUpperBound = intTempArray.GetUpperBound( 0 );



// print each row of the array

for ( int intI = 0; intI <= intUpperBound; intI++ )

{

lstArray.Items.Add( intTempArray[ intI, 0 ] +

"\t” + intTempArray[ intI, 1 ] +

"\t” + intTempArray[ intI, 2 ] +

"\t” + intTempArray[ intI, 3 ] );

}



} // end method FrmInitialize_Load



// initializes a 2D array to contain all 1's

int[,] TwoDArrays()

{

int[,] intArray = new int[ 4, 4 ];



// assign 1 to all cell values

for ( int intI = 0; intI < 4; intI++ )

{

for ( int intJ = 0; intJ < 4; intJ++ )

{

intArray[ intI, intJ ] = 1;

}

}

return intArray;



} // end method TwoDArrays



} // end class FrmInitialize

}



Computer Science & Information Technology

You might also like to view...

What is the range of wavelengths of visible light? What colors correspond to the shorter wavelengths?

What will be an ideal response?

Computer Science & Information Technology

Which of the following should be added before a number if you want to enter a number as a label, for example, as a telephone number?

A. slash B. double quote C. apostrophe D. pound

Computer Science & Information Technology

To convert a database to the Access 2003 format, you can use the Save As option and change the file format

Indicate whether the statement is true or false

Computer Science & Information Technology

Describe briefly what a layout with facing pages would look like.

What will be an ideal response?

Computer Science & Information Technology