Hi, I am having trouble sorting a client contact lists by their surname. Every time when I press the "sort by surname button, it always appear alphabetical order
by clients' first name, because I put them before the surname, it is the first String of the every line in the listBox.
My code under the sortBySurname is
Can someone tell me how to specify it to be sorted by clients' surname?
by clients' first name, because I put them before the surname, it is the first String of the every line in the listBox.
My code under the sortBySurname is
Code:
private void sortBySButton_Click(object sender, EventArgs e) { contactListBox.Items.Clear(); StreamReader fileReader; string[] myArray; string line = ""; string bigString = ""; fileReader = new StreamReader(@"c: \client contact details.txt"); while (fileReader.Peek() != -1) { line = fileReader.ReadLine(); bigString = bigString + line + "\n"; } fileReader.Close(); bigString = bigString.Trim(); myArray = bigString.Split('\n'); Array.Sort(myArray); foreach (string item in myArray) { contactListBox.Items.Add(item); } }
Comment