这就是我到目前为止所做的一切,一切都会好起来,直到它成为数组中的最后一个字符串
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);
}
}
答案 0 :(得分:3)
int i = 0;
while (true)
{
i = i % 3;
Console.Write("\r" + loading[i++]);
Thread.Sleep(500);
}
答案 1 :(得分:0)
如果你用一行写它会更好看:
public static void Main()
{
int loadingLength = 5;
Console.Write("Loading...");
for (int i = 0; i < loadingLength; i++)
Console.Write(".");
Thread.Sleep(500);
}
}
如果您仍然需要输出多行“加载”,请考虑生成长度为N的点串,而不是将它们全部存储在数组中。
提示:new string(char, count)
使用字符count
生成长度为char
的字符串。