namespace test
{
class Test6
{
static void Main(string[] args)
{
string str = "welcome to xfht";
//获取字符串str的长度
int length = str.Length;
//获取控制台窗口的宽度
int width=Console.WindowWidth;
//在字符串前添加width-length个空格
for (int i = 1; i <= width - length; i++)
{
str = " " + str;
}
int index = 0;
while (true)
{
Console.Clear();//清除控制台中显示的信息(清屏)
//截取字符串
string temp = str.Substring(index);
Console.Write(temp);
index++;
System.Threading.Thread.Sleep(100);
if (index > width)
{
index = 0;
}
}
}
}
}
C#实现跑马灯效果
最新推荐文章于 2023-11-29 20:49:48 发布