EDN Admin
Well-known member
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt I need Help with the saving and loading of my array. I tried several different things I found on the internet but no luck. Also
I was wondering how would I do an error loop for the menu, gives the user an error if anything other than 1-7 and q. I have it where only 1 digit can be entered
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt using<span style="font-family:"Courier New"; font-size:10pt System;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt using<span style="font-family:"Courier New"; font-size:10pt System.Collections.Generic;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt using<span style="font-family:"Courier New"; font-size:10pt System.Linq;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt using<span style="font-family:"Courier New"; font-size:10pt System.Text;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt using<span style="font-family:"Courier New"; font-size:10pt System.IO;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt namespace<span style="font-family:"Courier New"; font-size:10pt ConsoleApplication1
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt {
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue class <span style="color:#2b91af Program
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees = <span style="color:blue
new <span style="color:#2b91af Dictionary<<span style="color:blue string,
<span style="color:blue string>();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(<span style="color:#a31515 "Harpo", <span style="color:#a31515
"654-0987");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(<span style="color:#a31515 "Groucho", <span style="color:#a31515
"555-1234");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(<span style="color:#a31515 "Gummo", <span style="color:#a31515
"456-7890");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(<span style="color:#a31515 "Zeppo", <span style="color:#a31515
"867-5309");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(<span style="color:#a31515 "Chico", <span style="color:#a31515
"445-6789");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue char MenuAnswer;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.ForegroundColor = <span style="color:#2b91af
ConsoleColor.White;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue do
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
MenuAnswer = Menu();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue switch (MenuAnswer)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 1:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
viewEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 2:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
searchEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 3:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
addEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 4:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
deleteEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 5:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style=" sortEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 6:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
saveEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 7:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
loadEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 q:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Ending program" +
<span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue default:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style=" <span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Invalid selection"
+ <span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue while (MenuAnswer != <span style="color:#a31515
q);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue char Menu()
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue char userAnswer;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "===========================================");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Menu");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 1 to veiw all Employees");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 2 to find a Employee");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 3 to add Employee");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 4 to delete Employee");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 5 to sort records");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 6 to save records");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 7 to load records");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter q to quit: " +
<span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.Write(<span style="color:#a31515 "Enter selection: ");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue try
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
userAnswer = <span style="color:#2b91af Convert.ToChar(<span style="color:#2b91af Console.ReadLine());
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue catch
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.ForegroundColor = <span style="color:#2b91af
ConsoleColor.Red;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#2b91af Environment.NewLine +
<span style="color:#a31515 "Error - Menu Selection must be exactly 1 character");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
userAnswer = <span style="color:#a31515 0;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.ForegroundColor = <span style="color:#2b91af
ConsoleColor.White;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue return userAnswer;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void addEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter Employee Name: ");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string employeeName = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter Phone Number: ");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string employeeNum = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(employeeName, employeeNum);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Added." +
<span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void deleteEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter Employee Name: ");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string employeeToDelete = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue foreach (<span style="color:#2b91af String employee
<span style="color:blue in employees.Keys)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue if (employeeToDelete == employee)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Remove(employee);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#2b91af Environment.NewLine + employee +
<span style="color:#a31515 " has been deleted." + <span style="color:#2b91af
Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue return;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Sorry, no employee by that name..." +
<span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void sortEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#2b91af Environment.NewLine +
<span style="color:#a31515 "Sorted List of Employees" + <span style="color:#2b91af
Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af SortedDictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> tempSortedEmployees = <span style="color:blue
new <span style="color:#2b91af SortedDictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String>(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees = <span style="color:blue new <span style="color:#2b91af
Dictionary<<span style="color:blue string, <span style="color:blue
string>(tempSortedEmployees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue foreach (<span style="color:#2b91af KeyValuePair<<span style="color:#2b91af String,
<span style="color:#2b91af String> pair <span style="color:blue in employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(pair.Key + <span style="color:#a31515
" " + pair.Value);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void viewEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#2b91af Environment.NewLine +
<span style="color:#a31515 "List of Employees" + <span style="color:#2b91af
Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue foreach (<span style="color:#2b91af KeyValuePair<<span style="color:#2b91af String,
<span style="color:#2b91af String> pair <span style="color:blue in employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(pair.Key + <span style="color:#a31515
" " + pair.Value);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void searchEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.Write(<span style="color:#a31515 "Enter name of Employee: ");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string searchEmployee = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue foreach (<span style="color:#2b91af String employee
<span style="color:blue in employees.Keys)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue if (searchEmployee == employee)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#2b91af Environment.NewLine + employee +
<span style="color:#a31515 " " + employees[employee] + <span style="color:#2b91af
Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue return;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style=" }
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Sorry, no employee by that name..." +
<span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void saveEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Saving.");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string saveEmployee = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af FileStream save = <span style="color:blue
new <span style="color:#2b91af FileStream(<span style="color:#a31515 @"C:UsersPublicTestFolderWriteLines.txt",
<span style="color:#2b91af FileMode.Create, <span style="color:#2b91af FileAccess.Write);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af StreamWriter save2 = <span style="color:blue
new <span style="color:#2b91af StreamWriter(save);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue for (<span style="color:blue int i = 0; i < employees.Length; i++)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
save2.WriteLine(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
save2.Close();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
save.Close();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void loadEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "loading.");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string loadEmployee = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="margin:0in 0in 10pt <a name="x__GoBack <span style="font-family:Calibri; font-size:small
View the full article
I was wondering how would I do an error loop for the menu, gives the user an error if anything other than 1-7 and q. I have it where only 1 digit can be entered
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt using<span style="font-family:"Courier New"; font-size:10pt System;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt using<span style="font-family:"Courier New"; font-size:10pt System.Collections.Generic;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt using<span style="font-family:"Courier New"; font-size:10pt System.Linq;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt using<span style="font-family:"Courier New"; font-size:10pt System.Text;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt using<span style="font-family:"Courier New"; font-size:10pt System.IO;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; color:blue; font-size:10pt namespace<span style="font-family:"Courier New"; font-size:10pt ConsoleApplication1
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt {
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue class <span style="color:#2b91af Program
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue static <span style="color:blue void Main(<span style="color:blue string[] args)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees = <span style="color:blue
new <span style="color:#2b91af Dictionary<<span style="color:blue string,
<span style="color:blue string>();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(<span style="color:#a31515 "Harpo", <span style="color:#a31515
"654-0987");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(<span style="color:#a31515 "Groucho", <span style="color:#a31515
"555-1234");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(<span style="color:#a31515 "Gummo", <span style="color:#a31515
"456-7890");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(<span style="color:#a31515 "Zeppo", <span style="color:#a31515
"867-5309");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(<span style="color:#a31515 "Chico", <span style="color:#a31515
"445-6789");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue char MenuAnswer;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.ForegroundColor = <span style="color:#2b91af
ConsoleColor.White;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue do
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
MenuAnswer = Menu();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue switch (MenuAnswer)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 1:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
viewEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 2:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
searchEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 3:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
addEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 4:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
deleteEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 5:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style=" sortEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 6:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
saveEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 7:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
loadEmployee(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue case <span style="color:#a31515 q:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Ending program" +
<span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue default:
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style=" <span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Invalid selection"
+ <span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue break;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue while (MenuAnswer != <span style="color:#a31515
q);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue char Menu()
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue char userAnswer;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "===========================================");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Menu");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 1 to veiw all Employees");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 2 to find a Employee");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 3 to add Employee");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 4 to delete Employee");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 5 to sort records");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 6 to save records");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter 7 to load records");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter q to quit: " +
<span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.Write(<span style="color:#a31515 "Enter selection: ");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue try
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
userAnswer = <span style="color:#2b91af Convert.ToChar(<span style="color:#2b91af Console.ReadLine());
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue catch
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.ForegroundColor = <span style="color:#2b91af
ConsoleColor.Red;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#2b91af Environment.NewLine +
<span style="color:#a31515 "Error - Menu Selection must be exactly 1 character");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
userAnswer = <span style="color:#a31515 0;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.ForegroundColor = <span style="color:#2b91af
ConsoleColor.White;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue return userAnswer;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void addEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter Employee Name: ");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string employeeName = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter Phone Number: ");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string employeeNum = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Add(employeeName, employeeNum);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Added." +
<span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void deleteEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Enter Employee Name: ");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string employeeToDelete = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue foreach (<span style="color:#2b91af String employee
<span style="color:blue in employees.Keys)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue if (employeeToDelete == employee)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees.Remove(employee);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#2b91af Environment.NewLine + employee +
<span style="color:#a31515 " has been deleted." + <span style="color:#2b91af
Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue return;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Sorry, no employee by that name..." +
<span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void sortEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#2b91af Environment.NewLine +
<span style="color:#a31515 "Sorted List of Employees" + <span style="color:#2b91af
Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af SortedDictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> tempSortedEmployees = <span style="color:blue
new <span style="color:#2b91af SortedDictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String>(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
employees = <span style="color:blue new <span style="color:#2b91af
Dictionary<<span style="color:blue string, <span style="color:blue
string>(tempSortedEmployees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue foreach (<span style="color:#2b91af KeyValuePair<<span style="color:#2b91af String,
<span style="color:#2b91af String> pair <span style="color:blue in employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(pair.Key + <span style="color:#a31515
" " + pair.Value);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void viewEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#2b91af Environment.NewLine +
<span style="color:#a31515 "List of Employees" + <span style="color:#2b91af
Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue foreach (<span style="color:#2b91af KeyValuePair<<span style="color:#2b91af String,
<span style="color:#2b91af String> pair <span style="color:blue in employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(pair.Key + <span style="color:#a31515
" " + pair.Value);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void searchEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.Write(<span style="color:#a31515 "Enter name of Employee: ");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string searchEmployee = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue foreach (<span style="color:#2b91af String employee
<span style="color:blue in employees.Keys)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue if (searchEmployee == employee)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#2b91af Environment.NewLine + employee +
<span style="color:#a31515 " " + employees[employee] + <span style="color:#2b91af
Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue return;
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style=" }
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Sorry, no employee by that name..." +
<span style="color:#2b91af Environment.NewLine);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void saveEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "Saving.");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string saveEmployee = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af FileStream save = <span style="color:blue
new <span style="color:#2b91af FileStream(<span style="color:#a31515 @"C:UsersPublicTestFolderWriteLines.txt",
<span style="color:#2b91af FileMode.Create, <span style="color:#2b91af FileAccess.Write);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af StreamWriter save2 = <span style="color:blue
new <span style="color:#2b91af StreamWriter(save);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue for (<span style="color:blue int i = 0; i < employees.Length; i++)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
save2.WriteLine(employees);
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
save2.Close();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
save.Close();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue public <span style="color:blue static
<span style="color:blue void loadEmployee(<span style="color:#2b91af Dictionary<<span style="color:#2b91af String,
<span style="color:#2b91af String> employees)
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
{
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:#2b91af Console.WriteLine(<span style="color:#a31515 "loading.");
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<span style="color:blue string loadEmployee = <span style="color:#2b91af
Console.ReadLine();
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
}
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt <span style="
<p style="line-height:normal; margin:0in 0in 0pt <span style="font-family:"Courier New"; font-size:10pt
<p style="margin:0in 0in 10pt <a name="x__GoBack <span style="font-family:Calibri; font-size:small
View the full article