26

I came across this code today

AsyncInvoke(OnTimeMessageTimer, (object)null, (ElapsedEventArgs)null);

Is there anything wrong with it or no?

HerbalMart
  • 1,669
  • 3
  • 27
  • 50
sthay
  • 495
  • 1
  • 7
  • 16

2 Answers2

39

Sometimes, you need to to this when the method is overloaded... to tell the compiler which one you are calling. A null object is still null and it is safe.

Brian Genisio
  • 47,787
  • 16
  • 124
  • 167
4

it probably needs the cast to resolve overloads

Jimmy
  • 89,068
  • 17
  • 119
  • 137