Are there any benefits to using HtmlTextWriter if you are not going to benefit from adaptive rendering?

后端 未结 5 1249
北恋
北恋 2021-02-07 11:17

Outside of benefiting from Adaptive Rendering for alternate devices, does it ever make sense to write all of this code:

writer.WriteBeginTag(\"t         


        
5条回答
  •  心在旅途
    2021-02-07 11:46

    I can think of two reasons to use HtmlTextWriter:

    1. You can use the writer to keep track of your indents, so that your outputted HTML is formatted nicely, rather than appearing on one line

    2. HtmlTextWriter is usually associated with an output stream, so it should be more efficient than building up a long string in memory (depending upon how much HTML you are generating).

    Neither of these are extraordinary reasons, but they are enough to convince me to use the writer when efficiency is needed, or if I am writing a base control that will be reused and should be as professional as possible. Your mileage may vary :-).

提交回复
热议问题