Ipsum GetPhrase() Improvement

Jan 24, 2013 at 1:15 AM

The Ipsum GetPhrase() method is more efficient if it uses StringBuilder:


public static string GetPhrase(int wordCount)
{
        StringBuilder sb = new StringBuilder();
 
        sb.Append("Lorem");
        sb.Append(' ');
	sb.Append("ipsum");
        sb.Append(' ');
        sb.Append("dolor");
        sb.Append(' ');
        sb.Append("sit");
        sb.Append(' ');
        sb.Append("amet");
 
	for (int i = 5; i <= wordCount; i++)
	{
            sb.Append(' ');		
            sb.Append(words[random.Next(words.Length - 1)]);
	}
 
        sb.Append('.');
        
        return sb.ToString();
}