Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[C#]流れるHello World!
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
var width = 30;
var queue = QueueInit(width);
string target = "Hello World!" + Interval();
try
{
while (true)
{
foreach (var c in target)
{
Console.Write(Shift(queue, c.ToString()));
Console.SetCursorPosition(0, Console.CursorTop);
System.Threading.Thread.Sleep(100);
}
}
}
catch (Exception e)
{
Console.WriteLine();
Console.WriteLine(e.Message);
Console.ReadKey();
}
}
static string Interval()
{
var interval = 10;
var intervalStr = string.Empty;
for (int i = 0; i < interval; i++)
{
intervalStr += " ";
}
return intervalStr;
}
static Queue<string> QueueInit(int size)
{
var strings = new Queue<string>();
var initialStr = " ";
for (int i = 0; i < size; i++)
{
strings.Enqueue(initialStr);
}
return strings;
}
static void FIFO(Queue<string> queue, string s)
{
queue.Dequeue();
queue.Enqueue(s);
}
static string QueueToString(Queue<string> q)
{
var array = q.ToArray();
return string.Join("", array);
}
static string Shift(Queue<string> queue, string s)
{
FIFO(queue, s);
return QueueToString(queue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment