Diskuze: Soubor využívá jiný proces
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.

Člen

Zobrazeno 9 zpráv z 9.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication22
{
class Program
{
static void Main(string[] args)
{
string file_name = "data.txt";
int num_lines = File.ReadAllLines(file_name).Length;
string[] input = new string[num_lines];
string[] output = new string[num_lines];
while (1 < 2)
{
StreamReader sr_public = File.OpenText(file_name);
using (StreamReader sr = File.OpenText(file_name))
{
for (int i = 0; i < num_lines; i++)
{
string line = sr.ReadLine();
string[] line_split = line.Split(';');
input[i] = line_split[0];
output[i] = line_split[1];
}
}
string question = Console.ReadLine();
int index = Array.IndexOf(input, question);
if (index != -1)
{
Console.WriteLine(output[index]);
}
else
{
Console.WriteLine(question);
string answer = Console.ReadLine();
string save = sr_public + question + ";" + answer;
using (StreamWriter sw = new StreamWriter(file_name, true))
{
sw.WriteLine(save.Remove(0, 22));
}
}
}
}
}
}
Co to třeba zkusit pomocí tlačítka kódu? Kdo má tohle číst?
Když otvíráš 2x ten samý soubor, nediv se. Nebo ho máš otevřený normalně na desktopu a otvíráš je ještě zkus tvůj program.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication22
{
class Program
{
static void Main(string[] args)
{
string file_name = "data.txt";
int num_lines = File.ReadAllLines(file_name).Length;
string[] input = new string[num_lines];
string[] output = new string[num_lines];
while (1 < 2)
{
StreamReader sr_public = File.OpenText(file_name);
using (StreamReader sr = File.OpenText(file_name))
{
for (int i = 0; i < num_lines; i++)
{
string line = sr.ReadLine();
string[] line_split = line.Split(';');
input[i] = line_split[0];
output[i] = line_split[1];
}
}
string question = Console.ReadLine();
int index = Array.IndexOf(input, question);
if (index != -1)
{
Console.WriteLine(output[index]);
}
else
{
Console.WriteLine(question);
string answer = Console.ReadLine();
string save = sr_public + question + ";" + answer;
using (StreamWriter sw = new StreamWriter(file_name, true))
{
sw.WriteLine(save.Remove(0, 22));
}
}
}
}
}
}
a jak ho zavřít po načtení?
StreamReader sr_public = File.OpenText(file_name);
using (StreamReader sr = File.OpenText(file_name))
Mluvím o tomto...
už to funguje. Nevšiml jsem si toho
Díky
Zobrazeno 9 zpráv z 9.