相关疑难解决方法(0)

在C#中按字母顺序排序数组

希望有人能提供帮助.我创建了一个可变长度数组,它将接受多个名称输入.我现在想按字母顺序对数组进行排序,并将其返回到控制台屏幕.

我以为是Array.Sort(名字); 会为我这样做,但我得到一个异常抛出.我一直在看笔记,例子和在线,但似乎没有什么能与我正在做的事情相匹配.

到目前为止我已经完成了以下工作.我接近在这里撕扯我的头发!PS我一直试图弄清楚这几个小时,我已经30多岁了,试图学习自己,所以请不要只说"做你的功课"我试图解决这个问题而不能这样我需要有人来解释哪里出错了 这是一个星期天,我正在努力做额外的工作,没有任何笔记来完全覆盖这一点

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 < names.Length; i++)
            {
                Student s;
                Console.WriteLine("Please enter student {0}'s name", (i + 1));
                s.Name = Console.ReadLine();
                names[i] = s;
            }
            ***Array.Sort<Student>(names);*** …
Run Code Online (Sandbox Code Playgroud)

c# arrays sorting

15
推荐指数
3
解决办法
5万
查看次数

如何按字母排序字符串数组?

我有很多字符串的数组.如何按字母顺序对字符串进行排序?

c# arrays sorting

8
推荐指数
1
解决办法
3万
查看次数

标签 统计

arrays ×2

c# ×2

sorting ×2