Skip to content

Instantly share code, notes, and snippets.

using System.Collections.Generic;
using System;
public class Program
{
public static void Main()
{
int[] nums = new int[] {1,1,1,2,2,3};
Dictionary<string,int> numCount = new Dictionary<string,int>();
@jmsevold
jmsevold / event.cs
Last active May 28, 2016 17:45
The world's easiest event example.
/*
We begin with a situation:
- We want code elsewhere to run when something occurs at a particular point in
our application. The class that contains this will be the publisher of the event.
Notice I am not using the word "event" to avoid confusion.
- In this case, it is the printing of a string, which we see occurs in the PrintString() method. For some reason,
we give a shit about this.
1. Declare a delegate. This is the contract between the publisher and subscriber(s). It's saying "Any and all methods- which we
// Find the only element in an array that only occurs once.
// create an object storing the keys as the numbers, and the values as the occurrence
// find the key that has a value of 1, and return that key
let list = [1,1,2,2,3,3,4,5,5,6,6];
let uniqueNum = (nums) =>{
let numObj = numCount(nums);
using System;
public delegate void SimpleDelegate(int a,int b);
class Class1
{
// two methods handlers with the same signature as the delegate
static void product(int i,int j)
{
Console.WriteLine(i*j);
using System;
/*
Declare the delegate. In this case, double is the return type that the handler
must also mirror. The name of the delegate, SimpleDelegate, will be used to
strongly type the variable that will hold the instance of the delegate. It will be of type SimpleDelegate, NOT double.
*/
public delegate double SimpleDelegate(int a,int b);
class Class1
{
var nodeNotVisited = (list,item) => {
if (list.indexOf(item) === -1) {
return true;
}
return false;
};
A
/ \
class Node{
constructor(value,children=[]){
this.value = value;
this.children = children;
this.visited = false;
}
}
var node10 = new Node(10);
var node9 = new Node(9);
var node8 = new Node(8, [node9]);
class Queue {
constructor() {
this.items = [];
}
enq(obj) {
this.items.push(obj);
}
deq() {
class Queue {
constructor() {
this.items = [];
}
enq(obj) {
this.items.push(obj);
}
deq() {
class Queue {
constructor() {
this.items = [];
}
enq(obj) {
this.items.push(obj);
}