public static void Main(string[] args) { var builder = new HTMLBuilder("ul"); builder.AddChild("li", "hello").AddChild("li", "world"); Console.WriteLine(builder.ToString()); }
static void Main(string[] args) { //A builder for HTML elements //without builder var hello = "hello"; var sb = new StringBuilder(); sb.Append("<p>"); sb.Append(hello); sb.Append("</p>"); WriteLine(sb); var words = new[] { "hello", "world" }; sb.Clear(); sb.Append("<ul>"); foreach (var word in words) { sb.AppendFormat("<li>{0}</li>", word); } sb.Append("</ul>"); WriteLine(sb); //with builder var builder = new HTMLBuilder("ul"); builder.AddChild("li", "hello").AddChild("li", "world"); WriteLine(builder.ToString()); ReadKey(); }