希望有人能提供帮助.我创建了一个可变长度数组,它将接受多个名称输入.我现在想按字母顺序对数组进行排序,并将其返回到控制台屏幕.
我以为是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) 目前,我正在读取特定条目"X"的文件.一旦我找到这个条目,我可以在任何后续行中做我需要做的事情但是在"X"出现之前有一条信息需要2行.现在我可以使用var line = reader.ReadLine();在文件中前进并读取"X"之后的行.我如何回过头来读取2行数据?
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (line.Contains("X"))
{
Processing
}
}
Run Code Online (Sandbox Code Playgroud)