I'm fairly new in C# and just encountered a weird behavior.
This is a piece of script that should sort array of strings alphabetically (A-Z)
This is the array:
IFF-7/12
IFA-7/11
IFF-7/8
IFF-7/2
IFF-7/11
IFF-7/1
IF-7/1
IFF-7/6
IFF-7/9
IFF-7/13
IFF-7/14
IF-7/2
So I suppose the outcome should be:
IF-7/1
IF-7/2
IFA-7/11
IFF-7/1
IFF-7/2
IFF-7/6
IFF-7/8
IFF-7/9
IFF-7/11
IFF-7/12
IFF-7/13
IFF-7/14
Program script:
for (int i = 0; i < faculty.GroupCount; i++)
{
for (int j = i + 1; j < faculty.GroupCount; j++)
{
if (faculty.Groups[j].Name.CompareTo(faculty.Groups[i].Name) < 0)
{
temp = faculty.Groups[i];
faculty.Groups[i] = faculty.Groups[j];
faculty.Groups[j] = temp;
}
}
}
But the actual outcome is
IF-7/1
IF-7/2
IFA-7/11
IFF-7/1
IFF-7/11
IFF-7/12
IFF-7/13
IFF-7/14
IFF-7/2
IFF-7/6
IFF-7/8
IFF-7/9
I see what it's doing but I have no idea why. Also I can't use any of the libraries or methods like .sort .
Thanks for any help.