nooby nooby - 2 months ago 8
C# Question

c# how to make loading text simple

This is all I got so far, everything will go good until it gets too the last string in the array

private static String[] loading = {"Loading.", "Loading..", "Loading..."};

public static void Main(String[] args)
{
while (true)
{
for (int i = 0; loading.Length > i; i++)
{
Console.Write("\r" + loading[i]);
Thread.Sleep(500);
}
}

Answer

It would look better if you write it in a single line:

public static void Main()
{
    int loadingLength = 5;
    Console.Write("Loading...");

    for (int i = 0; i < loadingLength; i++)
        Console.Write(".");
        Thread.Sleep(500);
    }
}

If you still need to output many lines of "loading", think about generating string of dots of length N instead of storing them all in an array.
Tip: new string(char, count) generates string of length count using chars char.