Skip to content

Instantly share code, notes, and snippets.

@rstackhouse
Created August 8, 2017 02:05
Show Gist options
  • Save rstackhouse/c8756f012082196e17f5d11893d3437f to your computer and use it in GitHub Desktop.
Save rstackhouse/c8756f012082196e17f5d11893d3437f to your computer and use it in GitHub Desktop.
Message Box Using Generic List
class MessageBox
{
private List<string> messages = new List<string>();
public int MessageCount { get { return messages.Count; } }
public string this [int i]
{
get { return messages [i]; }
set { messages[i] = value; }
}
public void AddMessage(string message)
{
messages.Add(message);
}
public int FindMessage(string message)
{
for (var i = 0; i < messages.Count(); i++)
{
if (message == messages[i])
{
return i;
}
}
return -1;
}
public void RemoveMessage(string message)
{
var i = FindMessage(message);
if (i > -1)
{
messages.RemoveAt(i);
}
}
public override string ToString()
{
var sb = new System.Text.StringBuilder();
foreach(var s in messages)
{
sb.Append(s);
sb.Append('\n');
}
return sb.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment