Is it possible to overload the default function operator (the () operator) in C#? If so - how? If not, is there a workaround to create a similar affect?
Thanks,
You mention that you want to do logging, here is how you could do that with delegates:
FooBar MyAlgorithm(Foo paramA, Bar paramB, Actions logger) {
logger("Starting algorithm.")
FooBar result = ...;
logger("Finished algorithm.");
return result;
}
When you run this you could log to the console:
MyAlgorithm(a, b, (text) => Console.WriteLine(text));
Or log to a Windows Forms TextBox:
TextBox logbox = form.GetLogTextBox();
MyAlgorithm(a, b, (text) => logbox.Text += text + Environment.NewLine);