Skip to content

Instantly share code, notes, and snippets.

@ragavendra
Created June 14, 2024 20:38
Show Gist options
  • Save ragavendra/b9eb3e7b97720ccf7c393f158363ea28 to your computer and use it in GitHub Desktop.
Save ragavendra/b9eb3e7b97720ccf7c393f158363ea28 to your computer and use it in GitHub Desktop.
Callbacks in Csharp like CommonJS style
using System;
using System.Threading.Tasks;
public class Program
{
public static void Main()
{
ReadFile("", (err, data) => {
if(err != null) {
Console.WriteLine("Err");
return;
}
Console.WriteLine("Data " + data);
});
Console.WriteLine("Hello World");
}
private static Task ReadFile(string path, Action<string, string> action) {
var no = new Random().Next(0, 100);
if (no % 2 == 0)
action(null, "completed");
else
action("err", null);
return default;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment