I'm using parallel arrays to display names and grades of students. I am stuck at displaying the arrays. I get System.String[] instead of the input value I want. This is my code what am I doing wrong:
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Parrallel_Arrays {
public partial class frmGrades : Form {
String nameString = "Aaron Ben Carmelina Dorethy Erinn Karin " +
"Lester Mitsue Nichol Ria Sherie Zachary";
String assignmentsString = "44 92 100 100 100 97 100 95 100 0 100 100 " +
"95 95 97 90 100 95 100 100 100 100 100 75 " +
"98 100 65 0 100 100 100 100 100 100 95 75 " +
"85 100 0 50 100 95 90 0 80 100 100 100";
String[] arrayNames = new String[12];
String[,] arrayGrades = new String[4, 12];
String[] arrayAverage = new String[12];
public frmGrades() {
InitializeComponent();
}
private void frmGrades_Load(object sender, EventArgs e) {
}
//Method to Fill Array
private void FillArray(String[] name, String[,] grade) {
String[] arrayNames = { nameString };
String[,] arrayGrades = { { assignmentsString } };
String[] arrayAverage = { };
char[] separator = new char[] { ' ' };
String[] tokens = assignmentsString.Split(separator);
String[] token2 = nameString.Split(separator);
foreach (String token in tokens) ;
}
//Method to Display Array of names and assignment grades
private void DisplayArray(String[] nameString, String[,] assignmentsString) {
for (int i = 0; i < nameString.Length; i++) {
lbxDisplay.Items.Add(nameString[i] + " ");
}
}

Amira BedhiafiRank #601 · 4K reputationPosted Mar 19, 2025, 6:32 PM EDT
You need to properly split the nameString and assignmentsString into the respective arrays (arrayNames and arrayGrades).
You need to iterate through the arrays and add each element to the ListBox.
using System; using System.Windows.Forms; namespace Parallel_Arrays { public partial class frmGrades : Form { String nameString = "Aaron Ben Carmelina Dorethy Erinn Karin " + "Lester Mitsue Nichol Ria Sherie Zachary"; String assignmentsString = "44 92 100 100 100 97 100 95 100 0 100 100 " + "95 95 97 90 100 95 100 100 100 100 100 75 " + "98 100 65 0 100 100 100 100 100 100 95 75 " + "85 100 0 50 100 95 90 0 80 100 100 100"; String[] arrayNames = new String[12]; String[,] arrayGrades = new String[4, 12]; String[] arrayAverage = new String[12]; public frmGrades() { InitializeComponent(); } private void frmGrades_Load(object sender, EventArgs e) { FillArray(arrayNames, arrayGrades); DisplayArray(arrayNames, arrayGrades); } // Method to Fill Array private void FillArray(String[] name, String[,] grade) { char[] separator = new char[] { ' ' }; String[] names = nameString.Split(separator, StringSplitOptions.RemoveEmptyEntries); String[] grades = assignmentsString.Split(separator, StringSplitOptions.RemoveEmptyEntries); // Fill arrayNames for (int i = 0; i < names.Length; i++) { arrayNames[i] = names[i]; } // Fill arrayGrades int gradeIndex = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 12; j++) { arrayGrades[i, j] = grades[gradeIndex++]; } } } // Method to Display Array of names and assignment grades private void DisplayArray(String[] names, String[,] grades) { for (int i = 0; i < names.Length; i++) { string displayString = names[i] + ": "; for (int j = 0; j < 4; j++) { displayString += grades[j, i] + " "; } lbxDisplay.Items.Add(displayString); } } } }