I don’t have any experience in F# but have a few lines of test code in C# for a framework I've made that I need to rewrite in F#.
Any help would be appreciated.
bar.Ready += new Agent.ReadyHandler(bar_Ready);
static void bar_Ready(string msg)
{
Console.WriteLine(msg.body);
}
Just to clarify - the shorter version should correctly be:
bar.Ready.Add(fun msg -> System.Console.WriteLine(msg))
Because F# doesn't automatically convert lambda functions to delegates - but there is an Add method that takes a function. This can then be written even simpler like this:
bar.Ready.Add(System.Console.WriteLine)
Because F# allows you to use .NET members as first-class functions.
Try this -
bar.Ready.AddHandler(new Agent.ReadyHandler (fun sender msg -> System.Console.WriteLine(msg)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With