Untitled

mail@pastecode.io avatar
unknown
csharp
8 months ago
1.6 kB
4
Indexable
Never
string[] names = new string[]
{
    "name1",
    "name2",
    "name3",
    "name4"
};
int initialSize = names.Length;

while (true)
{
    initialSize = names.Length;

    Console.WriteLine("Welcome to Randomizer");
    Console.WriteLine("#####################");
    Console.WriteLine("1. Show all the names");
    Console.WriteLine("2. Add new names");
    Console.WriteLine("3. Generate random names");
    Console.WriteLine("4. Generate random commands");

    int inputComand = Convert.ToInt32(Console.ReadLine());

    switch (inputComand)
    {
        case 1:
            ShowNames();
            break;
        case 2:
            AddNames();
            break;
        case 3: RandomName();
            break;
        case 4:
            break;
    }
    Console.WriteLine("Pleas press any button to continue");
    Console.ReadKey();
    Console.Clear();
}
void ShowNames()
{
    foreach (string name in names)
    {
        Console.WriteLine(name);
    }
}

void AddNames()
{
    Console.WriteLine("Please type below the new names you want to add by space ...");
    string newNames = Console.ReadLine();
    string[] eachName = newNames.Split(' ');
    Array.Resize(ref names, names.Length + eachName.Length);
    for (int i = 0; i < eachName.Length; i++)
    {
        names.SetValue(eachName[i], initialSize + i);
    }
}

void RandomName()
{
    Console.WriteLine("Please advise how many names you want to generate randomly");
    int randomCount = Convert.ToInt32(Console.ReadLine());
    Random random = new Random();
    Console.WriteLine(names[randomCount]);

}
Leave a Comment