Write HTML to string

前端 未结 18 1563
一生所求
一生所求 2020-12-13 00:04

I have code like this. Is there a way to make it easier to write and maintain? Using C# .NET 3.5.

string header(string title)
{
    StringWriter s = new Stri         


        
18条回答
  •  难免孤独
    2020-12-13 00:33

    It really depends what you are going for, and specifically, what kind of performance you really need to offer.

    I've seen admirable solutions for strongly-typed HTML development (complete control models, be it ASP.NET Web Controls, or similar to it) that just add amazing complexity to a project. In other situations, it is perfect.

    In order of preference in the C# world,

    • ASP.NET Web Controls
    • ASP.NET primitives and HTML controls
    • XmlWriter and/or HtmlWriter
    • If doing Silverlight development with HTML interoperability, consider something strongly typed like link text
    • StringBuilder and other super primitives

提交回复
热议问题