C# :: Aufgabe #212 :: Lösung #4
4 Lösungen

#212
Einfacher Namensgenerator
Anfänger - C#
von Exception
- 30.05.2018 um 15:23 Uhr
Schreibe ein Programm, welches zwei Textdateien (zb Vorname.txt, Nachname.txt) Zeile für Zeile in ein Array lädt.
Gebe dann eine zufällige Kombination aus Vornamen und Nachnamen aus.
Gebe dann eine zufällige Kombination aus Vornamen und Nachnamen aus.
#4

von DBqFetti (2480 Punkte)
- 10.06.2018 um 09:36 Uhr

using System; using System.IO; using System.Linq; namespace TYP212 { class Program { const string FFIRST = "vornamen.txt", FLAST = "nachnamen.txt"; static readonly Random rnd = new Random(); static string[] first, last; static void Main() { if(!File.Exists(FFIRST) || !File.Exists(FLAST)) { return; } first = File.ReadAllLines(FFIRST).Distinct().ToArray(); last = File.ReadAllLines(FLAST).Distinct().ToArray(); do { Console.WriteLine($"{first[rnd.Next(first.Length)]} {last[rnd.Next(last.Length)]}"); } while(Console.ReadKey(true).Key != ConsoleKey.Escape); } } }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1