更新时间:2023-12-05 18:07:16
通过使用HtmlNode.GetAttributeValue
方法并将"margin-top" 魔术字符串设置为常数:
You could simplify your code a little bit by using HtmlNode.GetAttributeValue
method, and making your "margin-top" magic string as constant:
const string margin = "margin-top: 0";
foreach (var pTagNode in pTagNodes)
{
var styles = pTagNode.GetAttributeValue("style", null);
var separator = (styles == null ? null : "; ");
pTagNode.SetAttributeValue("style", styles + separator + margin);
}
不是很明显的改进,但是对于我来说,这段代码更简单.
Not a very significant improvement, but this code is simpler as for me.