Hope someone can help. I have created a variable length array that will accept several name inputs. I now want to sort the array in alphabetical order and return that to the
To sort by the name property of your Student objects in your Student array, you can use
Array.Sort(names, (s1, s2) => String.Compare(s1.Name, s2.Name));
which will sort your array in place, or with System.Linq:
names = names.OrderBy(s => s.Name).ToArray();
which can return the sorted IEnumerable as an array (.ToArray()) or a list (.ToList().)
Remember to sort case-insensitive if it matters, as pointed out in another answer, which can be done in String.Compare like so:
String.Compare(s1.Name, s2.Name, StringComparison.CurrentCultureIgnoreCase)