我剛剛意識到我不知道任何C#。在代表上使用+ =運算符不好嗎?
在委託實例上使用+=
和Delegate.Combine
有什麼區別?
例如,
public delegate void Printer(string s);
public class Program
{
public static void Main(string[] args)
{
Printer printer = new Printer((s) => { Console.WriteLine(s); });
// is it wrong to use this += operator
// on the delegate instance printer?
printer += s => {};
// And is this somewhat holier than the previous one?
// why?
Delegate.Combine(printer, new Printer((s) => {});
}
}
我問這個問題,因爲它似乎是由嗶嘰karalenka的回答這個線程上暗示:https://stackoverflow.com/a/15183049/303685
http://stackoverflow.com/questions/14197857/composing-multicast-delegates-in-c-sharp-shoud-i-use-operators-or-action-combi – TyCobb 2015-02-08 06:50:04