- 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#實現跑馬燈效果 .
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.