Skip to content

Instantly share code, notes, and snippets.

@b0urb4k1
Created September 22, 2021 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b0urb4k1/afb6f5ab929423153c12d93400497d55 to your computer and use it in GitHub Desktop.
Save b0urb4k1/afb6f5ab929423153c12d93400497d55 to your computer and use it in GitHub Desktop.
Virtual method capture
using System;
namespace test
{
public class C
{
public C()
{
}
public virtual string M() => "C";
public string X(Func<string> f) => f();
public string CallDelegate() => X(M);
}
public class CD : C
{
public override string M() => "CD";
}
class Program
{
static void Main(string[] args)
{
var x = new CD();
Console.WriteLine(x.CallDelegate());
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment