private void AddToList() { try { PersonData person = new PersonData(); //Declare an object from PersonData, in terms of PersonData Class, it could be store what user enters into TextBox Control and offer some methods. person.setPersonDetails(getUI_PersonDetails()); //Get what user enters from UI and store it into properties of Class. if (Check_TextBox(person.index, 3, "Employee ID") && Check_TextBox(person.name, 0, "Name") && Check_TextBox(person.payrate, 1, "Pay rate") && Check_TextBox(person.email, 2, "Email")) //Check context what user enters is vaild through Check_TextBox method. { string[] person_desc = { person.index, person.name, person.payrate, person.email }; //Declare an array as a value for add or change data to List . PersonList list = new PersonList(); //Declare an object from PersonList Class,this class offer some methods to control List in UI and store some global variables Waga_Tax Rate_Data = new Waga_Tax(); //Declare an object from Wage_Tax Class,this class offer some methods to set and get value in its properties and store some global variables. if (!list.Check_Key(person.index)) //According to Employment ID to decide whether to add new data to list or only change an existing data { list.Add_NewDataArrary(person.index, person_desc); // Add new data to List array. employee_list.ItemsSource = list.getArrayForList(); //Update data for the list through set the ItemSource of the list. //******Part 2 solution****** Rate_Data.AddRateToDictionary(person.index, person.payrate); //Add new rate into Dictionary. } else { list.Change_Data(person.index, person_desc); employee_list.ItemsSource = list.getArrayForList(); //******Part 2 solution****** Rate_Data.ChangeRateToDictionary(person.index, person.payrate); //Change new rate into Dictionary. } MessageBox.Show("Success!", "Great!"); } } catch (Exception e) { MessageBox.Show($"Sorry,seems something wrong:{Environment.NewLine}{e}", "Error"); } }