Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting an array alphabetically in C#
    primarykey
    data
    text
    <p>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 console screen.</p> <p>I thought that Array.Sort(names); would do this for me but I am getting an exception thrown. I have been looking at notes, examples and on-line but nothing seems to match what I am doing.</p> <p>I have done the below so far. I am close to tearing my hair out here! PS I have been trying to figure this out for hours and I am 30+ years old trying to learn myself, so please don't just say "Do your homework" I have tried to resolve this and can not so I need someone to explain where I am going wrong. It is a Sunday and I am trying to do extra work and have no notes to cover this exactly</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Student_Array { class Program { struct Student { public string Name; } static void Main(string[] args) { int numberOfStudents; Student[] names; string input; Console.WriteLine("How many students are there?"); input = Console.ReadLine(); numberOfStudents = int.Parse(input); names = new Student[numberOfStudents]; for (int i = 0; i &lt; names.Length; i++) { Student s; Console.WriteLine("Please enter student {0}'s name", (i + 1)); s.Name = Console.ReadLine(); names[i] = s; } ***Array.Sort&lt;Student&gt;(names);*** for (int i = 0; i &lt; names.Length; i++) { Console.WriteLine(names[i].Name); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload