Created
August 8, 2017 02:05
-
-
Save rstackhouse/c8756f012082196e17f5d11893d3437f to your computer and use it in GitHub Desktop.
Message Box Using Generic List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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