Why use TagBuilder instead of StringBuilder?

后端 未结 6 1913
-上瘾入骨i
-上瘾入骨i 2020-12-13 18:04

what\'s the difference in using tag builder and string builder to create a table in a htmlhelper class, or using the HtmlTable?

aren\'t they generating the same thin

6条回答
  •  心在旅途
    2020-12-13 18:28

    It's just convenience. From this tutorial:

    You don’t really need to use the TagBuilder class. You could use a StringBuilder class instead. However, the TagBuilder class makes your life a little easier.

    Look at the methods on TagBuilder, and think about whether they give you value. would you want to do the same thing yourself manually in StringBuilder every time? Is there escaping that it does for you? Attribute merging, etc? Is the resulting code easier to read, making it clearer that you're building a tag rather than some arbitrary string?

提交回复
热议问题