我想创建一个派生自字符串构建器的类,以附加任意数量的字符串。 我的程序应允许用户输入自己的字符串数。
我能够以编程方式追加字符串,但我希望winforms程序的用户能够在程序中输入他的自定义字符串
示例用法:
// Format Post Data
StringBuilder postData = new StringBuilder();
postData.Append("dst");
postData.Append("&popup=true");
postData.Append(String.Format("&username={0}", USERNAME_Validate1));// reads username from username textbox
postData.Append(String.Format("&password={0}", PASSWORD_Validate1));// reads password from password textbox
//Write Post Data To Server
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
writer.Write(postData);
答案 0 :(得分:0)
@corak - 那个代码正是我想要的而不是
public static class StringBuilderExtension {
public static StringBuilder AppendAll(
this StringBuilder stringBuilder,
params string[] items
) {
foreach(var item in items) {
stringBuilder.Append(item);
}
return stringBuilder;
}
}