Skip to content

Instantly share code, notes, and snippets.

@121jigowatts
Created December 14, 2016 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 121jigowatts/35ab7dbaadc48e7cef0010c51f98da77 to your computer and use it in GitHub Desktop.
Save 121jigowatts/35ab7dbaadc48e7cef0010c51f98da77 to your computer and use it in GitHub Desktop.
[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