Created
August 29, 2019 14:19
-
-
Save lauromoura/3dff20b89a6610ed3a4a83d7156dd8b0 to your computer and use it in GitHub Desktop.
C#: Using value types as event arguments
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 NewArgs | |
{ | |
public class EventPlayground | |
{ | |
public event EventHandler<int> OnSelectedIndex; | |
public void Select(int x) { | |
OnSelectedIndex?.Invoke(this, x); | |
} | |
static void Main() | |
{ | |
var emitter = new EventPlayground(); | |
emitter.OnSelectedIndex += (object sender, int e) => | |
{ | |
Console.WriteLine($"Selected Index {e}"); | |
}; | |
emitter.Select(42); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment