C#?????StringBuilder??????????
???????????? ???????[ 2016/3/14 11:00:35 ] ??????????????????? .NET
??????????????StringBuilder??????????????
???????????????????????????select?????????
private static string BuilderSelectBox(IDictionary<int?? string> options?? string id?? bool includeUnknown)
{
var html = new StringBuilder();
html.AppendFormat("<select id="{0}" name="{0}">"?? id);
html.AppendLine();
if(includeUnknown)
{
html.AppendLine(" <option>Unknown</option>");
}
foreach(var opt in options)
{
html.AppendFormat(" <option value="{0}">{1}</option>"?? opt.Key?? opt.Value);
html.AppendLine();
}
html.AppendLine("</select>");
return html.ToString();
}
?????????
????html.AppendFormat("<select id="{0}" name="{0}">"?? id);
????html.AppendLine();
?????????????????????????StringBuilder??
???????
public static class StringBuilderExtensions
{
public static StringBuilder AppendFormattedLine(this StringBuilder @this?? string format?? prams object[] args) => @this.AppendFormat(format?? args).AppendLine();
}
private static string BuilderSelectBox(IDictionary<int?? string> options?? string id?? bool includeUnknown)
{
var html = new StringBuilder()
.AppendFormattedLine("<select id="{0}" name="{0}">"?? id);
if(includeUnknown)
{
html.AppendLine(" <option>Unknown</option>");
}
foreach(var opt in options)
{
html.AppendFormattedLine(" <option value="{0}">{1}</option>"?? opt.Key?? opt.Value);
html.AppendLine();
}
html.AppendLine("</select>");
return html.ToString();
}
?????????
????if(includeUnknown)
????{
????html.AppendLine(" <option>Unknown</option>");
????}
??????????????????з???????????StringBuilder.
public static class StringBuilderExtensions
{
public static StringBuilder AppendFormattedLine(this StringBuilder @this?? string format?? prams object[] args) => @this.AppendFormat(format?? args).AppendLine();
public static StringBuilder AppendLineWhen(this StringBuilder @this?? Func<bool> predicate?? string value) =>
predicate()
? @this.AppendLine(value)
: @this;
}
private static string BuilderSelectBox(IDictionary<int?? string> options?? string id?? bool includeUnknown)
{
var html = new StringBuilder()
.AppendFormattedLine("<select id="{0}" name="{0}">"?? id)
.AppendLineWhen(() => includeUnknown?? " <option>Unknown</option>");
foreach(var opt in options)
{
html.AppendFormattedLine(" <option value="{0}">{1}</option>"?? opt.Key?? opt.Value);
}
html.AppendLine("</select>");
return html.ToString();
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11