利用队列
private Queue<string> logQueue = new Queue<string>();
private const int logMax = 100;
public void Log(string logText)
{
// this should only ever run for 1 loop as you should never go over logMax
// but if you accidentally manually added to the logQueue - then this would
// re-adjust you back down to the desired number of log items.
while (logQueue.Count > logMax - 1)
logQueue.Dequeue();
logQueue.Enqueue(logText);
textBox.Text = string.Join(Environment.NewLine, logQueue.ToArray());
}
来源:https://stackoverflow.com/questions/18988170/making-a-net-textbox-work-fifo-style