Skip to content

Instantly share code, notes, and snippets.

@jutikorn
Created January 3, 2017 07:57
Show Gist options
  • Save jutikorn/21d0c6385fac05b61985fa4efde6c1d3 to your computer and use it in GitHub Desktop.
Save jutikorn/21d0c6385fac05b61985fa4efde6c1d3 to your computer and use it in GitHub Desktop.
public class StringAppend
{
public delegate void StringOverflow(object sender, int Overflow);
public event StringOverflow StringOverflow_EventHandle;
}
class Program
{
void Main(string[] args)
{
StringAppend sa = new StringAppend();
sa.StringOverflow_EventHandle += new StringAppend.StringOverflow(string_over);
sa.StringOverflow_EventHandle += string_over;
sa.StringOverflow_EventHandle += (sender, Overflow) => { };
sa.StringOverflow_EventHandle += delegate {
};
}
private void string_over(object sender, int num_over)
{
}
}
@aaronamm
Copy link

aaronamm commented Jan 3, 2017

line 15 your handler is in StringAppend class. Therefore you need to create object of that class first and then use the handler method.
you can rewrite something like this.

var stringAppend = new StringAppend();
sa.StringOverflow_EventHandle += stringAppend.StringOverflow(string_over);

but for line 16 that handler method is in a class therefore you don't need to create new object, just use method directly in optional you can use this keyword.

 16           sa.StringOverflow_EventHandle += this.string_over;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment