Created
August 17, 2018 13:57
-
-
Save kumpera/5541e79c4564aaaffcb10132e4e6ca65 to your computer and use it in GitHub Desktop.
Traits for C#
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
interface BinaryOp { | |
int Apply (int a, int b); | |
} | |
struct Multiply { | |
public int Apply (int a, int b) { | |
return a * b; | |
} | |
} | |
static void Main () { | |
var m = new Multiply (); | |
var t = Trait<BinaryOp>.Make (ref m); //takes a ref, no boxing. | |
var res = t.As ().Apply (10, 20); // == 200 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment