Hi folks,
There are some cases when you need to pass an empty EventArgs to an event handler. I’ve been seeing the following code (which makes me really sick) lately over and over again:

MyEventHandler(this, new EventArgs());

Take a look at MSDN and you’ll see there’s a static read only field named Empty in the EventArgs class to be used in such scenarios. Therefore, the correct way to make the above call follows:

MyEventHandler(this, EventArgs.Empty);

The framework also contains more classes with the Empty field, say, String, Type, Color, Point and Size to name a few:

  • String.Empty means the literal ” “.
  • Color.Empty means “new Color()”.
  • Point.Empty means “new Point()”.
  • Size.Empty means “new Size()”
  • Rectangle.Empty means “new Rectangle()”
  • Type.EmptyTypes means “new Type[] { }”.

Happy coding!

 

One Response to Empty Fields

  1. Reza Shirazi says:

    Salam Mehdi jaan, man Reza Shirazi hastam, ghablan yeki az post haye toro toye codeproject dideh boodam, emroz ham yek post e dige didam dar morede isapi, baram kheili jaleb bood ke yek barname nevise khob mesle to dar iran darim, va az on jalebtar in bood ke dar bazi zamine haye moshtarak baa ham kaar kardim. mesle post e marbot be flicker ke zadeh boodi baram jaleb bood, man yek application be esme flishr neveshtam ke baraye kaar baa flickr be soorate offline hast, addressesh : http://www.flishr.com hast va mitoni free downloadesh koni.

    yek soal ham dashtam azat, man alan dargire yek proje hastam ke mikham user haa zamani ke ozv yek site shodan barashon dar iis domain be soorate khodkar add beshe. mikhastam bebinam ke aya dar in zamine tajrobe ee dari yaa na? agar dari mamnon misham ke rahnamaee koni mano.

    agar tamayol dashti baa address e reza.shirazi@gmail.com baa man ertebat bargharar kon.

    baa tashakor,
    Reza Shirazi

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Recent Tweets

TypeScript 2.4 released: Dynamic import(), string enums, improved generic inference and checking, plus more. blogs.msdn.microsoft.com/typescript/201… Retweeted by Mehdi Mousavi

Sponsors