我对C#和ASP.NET完全陌生。我遇到了这个问题...好吧,无论如何,我写了一些C#代码,假设是从25个人中选出前10个人,并在被要求时选择下一组10个人。该代码写在名为HelloWorldController.cs的文件中。它叫做
public static void Names() {...} .
我想用
来称呼它public IActionResult Index() {
return View();
}
然后在名为Index.cshtml的文件中调用它。
我绝对不知道我在做什么或如何使我的东西正常工作。我想要的只是我的c#程序以某种方式加载。我不知道该怎么做,我已经搜索了整个互联网,但没有真正找到可以帮助解决我的问题的东西。
请帮助我,我只是一个14岁的孩子,试图写一些代码来打动我的父亲老板。
c#代码名称:
public void Names() {
int y = 21;
while (true) {
Console.WriteLine("Listening...");
string command = Console.ReadLine();
if (command == "/info") {
Console.WriteLine("Here are the programs commands.");
Console.WriteLine("/replace a person");
Console.WriteLine("/exit");
Console.WriteLine("/info");
continue;
}
if (command == "/exit") {
return;
}
/*else {
if (!isNumber(command)) {
Console.WriteLine("You must enter a number.");
continue;
}
}*/
if (isNumber(command)) {
File.WriteAllText(@"lastlist.txt", String.Empty);
int x = Convert.ToInt32(command);
for (int i = 0; i < x; i++) {
var lines = System.IO.File.ReadAllLines(@"file.txt");
var filteredLines = lines.Where(l => l.StartsWith(y + "."));
foreach(var l in filteredLines)
{
Console.WriteLine(l);
System.IO.File.AppendAllText(@"lastlist.txt", l + "\r\n");
}
//y++;
//Random rnd1 = new Random();
//Console.WriteLine(lines[rnd1.Next(lines.Length)]);
//Console.WriteLine(lines[(lines.Length)]);
if (y > 24) {
y = 1;
}
else {
y++;
}
}
string text = System.IO.File.ReadAllText("Program.cs");
text = text.Replace("int y = 21;", "int y = " + y + ";");
System.IO.File.WriteAllText("Program.cs", text);
}
//Console.WriteLine("Press Enter for next batch of people.");
//Console.ReadLine();
//Console.WriteLine("Listenig...");
//string lastcommand = Console.ReadLine();
if (command == "/replace a person") {
Console.WriteLine("Enter name of a person to replace.");
string person1 = Console.ReadLine();
Console.WriteLine("Enter name of a person to replace with.");
string person2 = Console.ReadLine();
string text1 = System.IO.File.ReadAllText("file.txt");
text1 = text1.Replace(person1, person1 + "Switching...");
text1 = text1.Replace(person2, person2 + "Switching...");
text1 = text1.Replace(person1 + "Switching...", person2);
text1 = text1.Replace(person2 + "Switching...", person1);
System.IO.File.WriteAllText("file.txt", text1);
string text2 = System.IO.File.ReadAllText("lastlist.txt");
text2 = text2.Replace(person1, person1 + "Switching...");
text2 = text2.Replace(person2, person2 + "Switching...");
text2 = text2.Replace(person1 + "Switching...", person2);
text2 = text2.Replace(person2 + "Switching...", person1);
System.IO.File.WriteAllText("lastlist.txt", text2);
string newlastlist = System.IO.File.ReadAllText(@"lastlist.txt");
continue;
}
//if (lastcommand == "/exit") {
// return;
//}
//else {
continue;
//}
}
}