[Help] c# Bubblesort

I have to read in names from a file which look like: Lastname Firstname I then have to sort, using bubble sort, the names into ascending alphabetical order by last name. If the last names are the same, then compare the first names.

my function looks like this:

public static void OptBubbleSort(NameRec[] nList) { string temp; for (int botInd = nList.Length - 1; botInd > 0; botInd--) { for (int index = botInd - 1; index < nList.Length; index++) { if ((nList[index].LName).CompareTo(nList[index].LName) > 0) { temp = nList[index].LName; nList[index].LName = nList[index + 1].LName; nList[index + 1].LName = temp; } else if ((nList[index].LName).CompareTo(nList[index + 1].LName) == 0) { if ((nList[index].FName).CompareTo(nList[index + 1].FName) > 0) { temp = nList[index].FName; nList[index].FName = nList[index + 1].FName; nList[index + 1].FName = temp; } } } } } 

I am getting an error here:

 if ((nList[index].LName).CompareTo(nList[index].LName) > 0) 

It says: http://ift.tt/1G2XQmm

Any help would be great.

Full code: http://ift.tt/1EqZ2kR in case it is needed

by spencerknows via /r/csharp

Leave a Reply