Created
September 22, 2021 07:43
-
-
Save b0urb4k1/afb6f5ab929423153c12d93400497d55 to your computer and use it in GitHub Desktop.
Virtual method capture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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