This is just an experienting/learning example. I’m an extreme functional noob.
F# code to be used from C#:
module C
open System
open System.Collections.Generic
let Log format (f:Action<List<Object>>) =
let arguments = f.Invoke(new List<Object>())
let message = String.Format(format, arguments)
Console.Write(message)
C# code that calls it:
C.Log("Hello {0}", c =>
{
c.Add("World");
});
Expected Result
Hello World
Actual Result
Hello
The problem is you are creating a new
List<Object>and passing it to anAction<T>. AnAction<T>delegate doesn’t return any values hence you never get this list back. Instead theInvokemethod just returnsnullwhich is ignored in theString.Formatcall. You need to persist the list between the delegate invoke andString.FormatTry the following