Created
April 30, 2018 14:27
-
-
Save argiopetech/92bdc2ccbaa0d004d1d1678fe0a36e65 to your computer and use it in GitHub Desktop.
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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace EventsApp | |
{ | |
public class MyButton | |
{ | |
public event Action<bool> OnClick; | |
public void Clicked() | |
{ | |
if (OnClick != null) | |
{ | |
this.OnClick(true); | |
} | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
void adjacentProducts(IEnumerable<int> vals) | |
{ | |
var newVals = | |
vals.Zip(vals.Skip(1), (x, y) => x * y); | |
for (int i = 1; i < vals.Count(); ++i) | |
{ | |
Console.WriteLine(vals.ElementAt(i - 1) * vals.ElementAt(i)); | |
} | |
foreach (var v in newVals) | |
Console.WriteLine($"{v}"); | |
} | |
adjacentProducts(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); | |
void myFunction(bool myBool) | |
{ | |
Console.WriteLine("In a handler"); | |
} | |
MyButton b = new MyButton(); | |
b.Clicked(); | |
b.OnClick += myFunction; | |
b.OnClick += aBool => Console.WriteLine("Another event Handler"); | |
// Pretend that a button was pressed | |
b.Clicked(); | |
b.OnClick -= myFunction; | |
b.Clicked(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment