title: Is it better practice to use a few tag builders or a StringBuilder to generate an Object tag? ASP.NET MVC
body: <p>I wrote an HTML helper to generate a YouTube embed link. It has 3 parameters, YouTubeID, Width, and Height. I originally wrote it with a StringBuilder, but then I decided to try to use the TagBuilder (well, a few of them).</p>
  
  <p>Here are the two different returns:</p>
  
  <pre><code>//Tag Builder
  public static string YouTube(this HtmlHelper helper, string youtubeId, string width, string height)
  {
      const string vidSuffix = "&amp;amp;hl=en_US&amp;amp;fs=1";
      var url = "http://www.youtube.com/v/" + youtubeId + vidSuffix;
  
      var objBuilder = new TagBuilder("object");
      objBuilder.MergeAttribute("width",width);
      objBuilder.MergeAttribute("height",height);
  
      var movParamBuilder = new TagBuilder("param");
      movParamBuilder.MergeAttribute("name","movie");
      movParamBuilder.MergeAttribute("value",url);
  
      var fsParamBuilder = new TagBuilder("param");
      fsParamBuilder.MergeAttribute("name","allowFullScreen");
      fsParamBuilder.MergeAttribute("value","true");
  
      var saParamBuilder = new TagBuilder("param");
      saParamBuilder.MergeAttribute("name", "allowscriptaccess");
      saParamBuilder.MergeAttribute("value", "always");
  
      var embedBuilder = new TagBuilder("embed");
      embedBuilder.MergeAttribute("src",url);
      embedBuilder.MergeAttribute("type", "application/x-shockwave-flash");
      embedBuilder.MergeAttribute("allowscriptaccess","always");
      embedBuilder.MergeAttribute("allowfullscreen","true");
      embedBuilder.MergeAttribute("width",width);
      embedBuilder.MergeAttribute("height",height);
  
      objBuilder.InnerHtml = movParamBuilder.ToString(TagRenderMode.Normal) +
                             fsParamBuilder.ToString(TagRenderMode.Normal) +
                             saParamBuilder.ToString(TagRenderMode.Normal) +
                             embedBuilder.ToString(TagRenderMode.Normal);
  
      return objBuilder.ToString(TagRenderMode.Normal);
  }
  
  
  //StringBuilder
  public static string YouTube(this HtmlHelper helper, string youtubeId, string width, string height)
  {
      const string vidSuffix = "&amp;amp;hl=en_US&amp;amp;fs=1";
      var url = "http://www.youtube.com/v/" + youtubeId + vidSuffix;
  
      sb.AppendFormat("&lt;object width=\"{0}\" height=\"{1}\"&gt;", width, height);
      sb.AppendLine();
      sb.AppendFormat("&lt;param name=\"movie\" value=\"{0}\"&gt;",url);
      sb.AppendLine();
      sb.Append("&lt;/param&gt;&lt;param name=\"allowFullScreen\" value=\"true\"&gt;");
      sb.AppendLine();
      sb.AppendFormat("&lt;/param&gt;&lt;param name=\"allowscriptaccess\" value=\"always\"&gt;");
      sb.AppendLine();
      sb.AppendFormat(
          "&lt;/param&gt;&lt;embed src=\"{0}\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"{1}\" height=\"{2}\"&gt;",
          url, width, height);
      sb.AppendLine();
      sb.Append("&lt;/embed&gt;&lt;/object&gt;");
  
      return sb.ToString();
  }
  </code></pre>
  
  <p>Both of them generate the exact same code, except the StringBuilder adds a line break after each section.</p>
  
  <p>Any thoughts on which would be better, or if it even matters? Thanks!</p>