使用keyvaluepair构建的字符串是这样的:"name1 = v1&name2 = v2&name3 = v3"
我在做什么:
var sb = new StringBuilder();
foreach (var name in nameValues)
{
sb.AppendFormat("{0}={1}&", name.Key, name.Value);
}
//remove last '&' sign, this is what i think is ugly
sb.ToString().Remove(lastIndex);
Run Code Online (Sandbox Code Playgroud)
任何优雅的方法,以避免'&'符号的最后删除声明?
要使用如此强大的功能ConvertAll(),我必须转换IList为List,这很痛苦.
我正在阅读这篇博客:管道和过滤器模式
我对这段代码感到困惑:
public class Pipeline<T>
{
private readonly List<IOperation<T>> operations = new List<IOperation<T>>();
public Pipeline<T> Register(IOperation<T> operation)
{
operations.Add(operation);
return this;
}
public void Execute()
{
IEnumerable<T> current = new List<T>();
foreach (IOperation<T> operation in operations)
{
current = operation.Execute(current);
}
IEnumerator<T> enumerator = current.GetEnumerator();
while (enumerator.MoveNext());
}
}
Run Code Online (Sandbox Code Playgroud)
这句话的目的是什么: while(enumerator.MoveNext()); ?似乎这个代码是noop.
哪一个在复制字节块时有更好的性能?
我必须通过这样做:
Action action = () => { ..// };
object o = action;
Run Code Online (Sandbox Code Playgroud)
任何方式这样做:
object o = () =>{}; //this doesn't compile
Run Code Online (Sandbox Code Playgroud) 有没有办法在点击取消按钮解雇winform时优雅地禁用errorprovider的验证?验证总是在文本框失去焦点时发生,并且我不想在用户单击取消按钮时验证它,当用户单击取消时验证它有点愚蠢.
在Load事件中或在InitializeComponent()之后的构造函数中?
或者根本不重要?