Question: I need to know how to display a list from a different method in a new method in C#. I have a menu: 1. Add

I need to know how to display a list from a different method in a new method in C#.

I have a menu:

1. Add Student Information 2. Display Student Information

When "1" is hit I only need to be able to add student information

When "2" is hit I only need to be able to display information

How do I break these two apart in order to do that? When I try to create a method with just the code to display the list it doesn't recognize the list. What I have is below. I'd like to break this up into addGrad() and displayGradList()

public static void addGrad() { bool done;

do { done = false;

List listA = new List(); gradList gl = new gradList();

Console.WriteLine("Enter Student ID."); long userInput1 = Convert.ToInt32(Console.ReadLine()); gl.studID = userInput1;

Console.WriteLine();

Console.WriteLine("Enter Student Name."); string userInput2 = Console.ReadLine(); gl.studName = userInput2;

Console.WriteLine();

Console.WriteLine("Enter Student DOB. (MM/DD/YY) "); DateTime userInput3 = DateTime.Parse(Console.ReadLine()); gl.dateOfBirth = userInput3;

Console.WriteLine();

Console.WriteLine("Enter Student Major."); string userInput4 = Console.ReadLine(); gl.major = userInput4;

Console.WriteLine();

Console.WriteLine("Enter Student GPA."); float userInput9 = float.Parse(Console.ReadLine()); gl.gpa = userInput9;

Console.WriteLine();

Console.WriteLine("Enter Student Previous Degree."); string userInput5 = Console.ReadLine(); gl.previousDegree = userInput5;

Console.WriteLine();

Console.WriteLine("Enter Student Previous University."); string userInput6 = Console.ReadLine(); gl.previousUniversity = userInput6;

Console.WriteLine();

Console.WriteLine("Enter Student Undergrad Major."); string userInput7 = Console.ReadLine(); gl.undergradMajor = userInput7;

Console.WriteLine();

Console.WriteLine("Enter Student Undergrad GPA."); float userInput8 = float.Parse(Console.ReadLine()); gl.undergradGPA = userInput8;

Console.WriteLine();

Console.WriteLine("Are you done entering students? (y/n)"); string answer = Console.ReadLine();

if (answer == "y") { for (int i = 0; i < listA.Count; i++) { Console.WriteLine(listA[i].studName); Console.WriteLine(listA[i].studID); Console.WriteLine(listA[i].dateOfBirth); Console.WriteLine(listA[i].major); Console.WriteLine(listA[i].gpa); Console.WriteLine(listA[i].previousDegree); Console.WriteLine(listA[i].undergradMajor); Console.WriteLine(listA[i].undergradGPA); } Console.ReadLine(); done = true; } else { Console.WriteLine(); } } while (done == false);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!