Цикл пишет одинаковые строки в файл - C#
Формулировка задачи:
for (shet = 1; shet <= 2; shet++)
{
string[] s = { "a", "b", "c", "d", "i", "f", "g", "h", "j", "o", "p" };
string s1 = s[new Random().Next(s.Length)];
if ( s1 =="a" )
{
s1 = a;
}
if (s1 == "b")
{
s1 = b;
}
if (s1 == "c")
{
s1 = c;
}
if (s1 == "d")
{
s1 = d;
}
if (s1 == "i")
{
s1 = i;
}
if (s1 == "f")
{
s1 = f;
}
if (s1 == "g")
{
s1 = g;
}
if (s1 == "h")
{
s1 = h;
}
if (s1 == "j")
{
s1 = j;
}
System.IO.File.AppendAllText("C:\\pass\\Passwords.txt", string.Format("\n{0}", s1));
}Решение задачи: «Цикл пишет одинаковые строки в файл»
textual
Листинг программы
using System;
using System.IO;
using System.Threading;
namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
string a = "aa";
string b = "bb";
string c = "cc";
string d = "dd";
string i = "ii";
string f = "ff";
string g = "gg";
string h = "hh";
string j = "jj";
Directory.CreateDirectory("C:\\pass\");
for (int shet = 1; shet <= 100; shet++)
{
string[] s = { "a", "b", "c", "d", "i", "f", "g", "h", "j", "o", "p" };
Thread.Sleep(10);
string s1 = s[new Random().Next(s.Length)];
if (s1 == "a")
{
s1 = a;
}
if (s1 == "b")
{
s1 = b;
}
if (s1 == "c")
{
s1 = c;
}
if (s1 == "d")
{
s1 = d;
}
if (s1 == "i")
{
s1 = i;
}
if (s1 == "f")
{
s1 = f;
}
if (s1 == "g")
{
s1 = g;
}
if (s1 == "h")
{
s1 = h;
}
if (s1 == "j")
{
s1 = j;
}
System.IO.File.AppendAllText("C:\\pass\\Passwords.txt", string.Format("\n{0}", s1));
}
}
}
}