Question

Microsoft Visual Studio in C#: I have this code and need to loop through each element...

Microsoft Visual Studio in C#: I have this code and need to loop through each element of the patient's array and add to a listbox (lbAccountDisplay) each property of the patient's object. This is the 2nd time to ask this question; it should have all the detail you need to help me. It is a piece of a project and I am trying not to give you the whole project. How do I use a foreach loop to loop through each element of the patient's array and add to a listbox (lbAccountDisplay) each property of the patient's object??

//Patients displayed in an array and displayed to AccountDisplay
//Initialize Array of Patients
const int SIZE = 4;
patients = new Patient_Class[SIZE];
patients[0] = new Patient_Class("Ava Hal", 0);
patients[1] = new Patient_Class("Jen Jacobson", 0);
patients[2] = new Patient_Class("Falicia Singh", 0);
patients[3] = new Patient_Class("All Williams", 0);

Homework Answers

Answer #1

NOTE :HERE Patient_Class IS CREATED FOR UNDERSTANDING PURPOSE ONLY

Application name :PatientsApplication

Language used :C#

Form1.cs :

//namespace
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;
//application namespace
namespace PatientsApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//display button click
private void buttonAdd_Click(object sender, EventArgs e)
{
  
const int SIZE = 4;
//creating array of Patients
Patient_Class []patients = new Patient_Class[SIZE];
//Initialize Array of Patients
patients[0] = new Patient_Class("Ava Hal", 0);
patients[1] = new Patient_Class("Jen Jacobson", 0);
patients[2] = new Patient_Class("Falicia Singh", 0);
patients[3] = new Patient_Class("All Williams", 0);
//using for each loop
foreach (Patient_Class patient in patients)
{
//display patient name and number in the listbox
lbAccountDisplay.Items.Add(patient.patientName+" "+patient.patientNumber);
}


}
}
class Patient_Class //C# class
{
public string patientName;
public int patientNumber;
//parameterized constructor
public Patient_Class(String name,int number)
{
this.patientName = name;
this.patientNumber = number;

}
}
}
=========================================='

Output :

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I have trouble in my code with - Create and append the fancySheet link element to...
I have trouble in my code with - Create and append the fancySheet link element to the document head - Create and append figBox element to element with id box - Populate the figure box with preview images of the five fancy style sheets I don't understand what went wrong. New Perspectives HMTL5, CSS3, and JavaScript T12 Case Problem 1: New Accents Photography JavaScript File Event Listener Go to the na_styler.js file in your editor. Add an event listener that...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i is saved in the array ascend[], in order. Compile and run the program; it should print 0 4 5. In this exercise, you’ll try to translate the C++ program to MIPS. Some of the more tedious parts are already given in Assignment3.F19.s. You won’t have to write the data allocation sections, some of the initializations, and the output loop at the end. So the...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
I am trying to make a program in C# and was wondering how it could be...
I am trying to make a program in C# and was wondering how it could be done based on the given instructions. Here is the code that i have so far... namespace Conversions { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...