{"id":27,"date":"2008-05-03T19:22:00","date_gmt":"2008-05-03T19:22:00","guid":{"rendered":"http:\/\/localhost:10265\/?p=26"},"modified":"2008-05-03T19:22:00","modified_gmt":"2008-05-03T19:22:00","slug":"empty-fields","status":"publish","type":"post","link":"https:\/\/mehdi.biz\/blog\/2008\/05\/03\/empty-fields\/","title":{"rendered":"Empty Fields"},"content":{"rendered":"<!-- google_ad_section_start --><p>Hi folks,<br \/>\nThere are some cases when you need to pass an empty EventArgs to an event handler. I&#8217;ve been seeing the following code (which makes me really sick) lately over and over again:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nMyEventHandler(this, new EventArgs());\n<\/pre>\n<p>Take a look at MSDN and you&#8217;ll see there&#8217;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:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nMyEventHandler(this, EventArgs.Empty);\n<\/pre>\n<p>The framework also contains more classes with the Empty field, say, String, Type, Color, Point and Size to name a few:<\/p>\n<ul>\n<li><b>String.Empty<\/b> means the literal &#8221; &#8220;.<\/li>\n<li><b>Color.Empty<\/b> means &#8220;new Color()&#8221;.<\/li>\n<li><b>Point.Empty<\/b> means &#8220;new Point()&#8221;.<\/li>\n<li><b>Size.Empty<\/b> means &#8220;new Size()&#8221;<\/li>\n<li><b>Rectangle.Empty<\/b> means &#8220;new Rectangle()&#8221;<\/li>\n<li><b>Type.EmptyTypes<\/b> means &#8220;new Type[] { }&#8221;.<\/li>\n<\/ul>\n<p>Happy coding!<\/p>\n<!-- google_ad_section_end -->","protected":false},"excerpt":{"rendered":"<p>Hi folks,<br \/> There are some cases when you need to pass an empty EventArgs to an event handler. I&#8217;ve been seeing the following code (which makes me really sick) lately over and over again:<\/p>\n<p> MyEventHandler(this, new EventArgs()); <\/p>\n<p>Take a look at MSDN and you&#8217;ll see there&#8217;s a static read only field named Empty in [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-27","post","type-post","status-publish","format-standard","hentry","category-csharp"],"_links":{"self":[{"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/posts\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/comments?post=27"}],"version-history":[{"count":0,"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"wp:attachment":[{"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}