私は、Visual Studio内のC#コンソールアプリケーションを使用して大学生向けの登録プログラムを作成しています。私は外部ファイルの1つで問題が発生しました。どうやらそれは現在、別のプログラムで使用されており、修正方法を見つけることができません。今現在使用中の外部ファイルの問題
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Class_Register_V1._0
{
class Program
{
static void Main(string[] args)
{
int monday, tuesday, wednesday, thursday, friday, classSize, weekCount, periodsPerWeek, counter, count, Value, input2, Outcome;
string answer, input, test;
Value = 0;
Outcome = 0;
StreamReader Size = new StreamReader(@"C:\Users\Dannys\Desktop\RegisterArraySize.txt");
count = Convert.ToInt32(Size.ReadLine());
Size.Close();
int newV = count - 1;
int[] myListOfUsername = new int[count];
StreamReader LogIn = new StreamReader(@"C:\Users\Dannys\Desktop\RegisterLogIn.txt");
for (int NewA = 0; NewA < count; NewA++)
{
myListOfUsername[NewA] = Convert.ToInt32(LogIn.ReadLine());
}
Console.WriteLine("Welcome to CodeTown's ClassLogIn.");
Console.WriteLine("1. login\n2. Register\n3. Exit");
input = Console.ReadLine();
input2 = Convert.ToInt32(input);
Console.Clear();
switch (input)
{
case "1":
do
{
Console.WriteLine("Please enter your login");
Value = Convert.ToInt32(Console.ReadLine());
for (int NewB = 0; NewB < count; NewB++)
{
if (Value == myListOfUsername[NewB])
{
Outcome = 1;
Console.Clear();
}
}
if (Outcome == 0)
{
Console.WriteLine("Login not recognised");
Console.ReadKey();
Console.Clear();
}
} while (Outcome == 0);
break;
case "2":
{
do
{
Console.WriteLine("Create 6 number Login ID\ni.e. 936548");
test = Console.ReadLine();
if (test.Length > 6)
{
Console.Clear();
Console.WriteLine("The login you used was too long!");
Console.ReadKey();
}
if (test.Length < 6)
{
Console.Clear();
Console.WriteLine("The login you used was too short!");
Console.ReadKey();
}
Console.Clear();
} while (test.Length != 6);
count++;
newV = count - 1;
int[] ListOfUsername = new int[count];
StreamReader LogInCreate = new StreamReader(@"C:\Users\Dannys\Desktop\RegisterLogIn.txt");
for (int NewC = 0; NewC < count; NewC++)
{
ListOfUsername[NewC] = Convert.ToInt32(LogIn.ReadLine());
}
ListOfUsername[newV] = Convert.ToInt32(test);
Console.WriteLine("Login will be registered once ClassLogIn has been restarted.\nWelcome abord!");
StreamWriter array = new StreamWriter(@"C:\Users\Dannys\Desktop\RegisterArraySize.txt");
array.WriteLine(count);
array.Close();
StreamWriter LogInWrite = new StreamWriter(@"C:\Users\Dannys\Desktop\RegisterLogIn.txt");
for (int NewD = 0; NewD < count; NewD++)
{
LogInWrite.WriteLine(ListOfUsername[NewD]);
}
LogInWrite.Close();
Console.ReadKey();
Console.Clear();
}
break;
case "3":
{
}
break;
}
}
}
}
、エラーを作成しているスニペット:
StreamWriter LogInWrite = new StreamWriter(@"C:\Users\Dannys\Desktop\RegisterLogIn.txt");
for (int NewD = 0; NewD < count; NewD++)
{
LogInWrite.WriteLine(ListOfUsername[NewD]);
}
LogInWrite.Close();
それが実際に書き込まないよう、あなたが一度だけファイルごとWriteLineメソッドを使用することができることになり、これを引き起こしている可能性が何のために私の唯一の思想それはコンソールのような行なので、すべてのユーザー名に対して新しいファイルを作成する必要があります。これが実際に問題であれば、6桁のtxtファイルの無限リストを私の唯一のオプションとして作成するためにループを使用していますか? ありがとうございます!
、私は今あなたが何を意味するのかを理解します!ありがとうございます –
申し訳ありません私は自分の携帯電話でコードを投稿するのが難しいです –