Extension methods are interesting

Not my idea, but it amused me. Thanks Dave.

namespace ExtensionMethodsAreEvil
 class ExtensionMethodsAreEvil
 public static void Main()
 string myNullString = null;
 Console.WriteLine("Is the string empty? " + myNullString.IsNullOrEmpty());

 public static class ExtendString
 public static bool IsNullOrEmpty(this string s)
 return string.IsNullOrEmpty(s);

About these ads

4 Responses to “Extension methods are interesting”

  1. Julien Says:

    I’m missing the point, sorry Dave :-)!

    I would also add that it is a very border line usage in my opinion, because it’s changing an important behaviour of the framework, that is throwing exceptions when calling a method on a null object.
    When you start changing basic behaviours such as these, god knows where you’ll end up :-)

  2. test0191 Says:

    Sorry I should have put “interesting”; i.e., horrible! This is completely wrong, wrong, wrong. But it works as comedy, I think.

  3. Julien Says:

    Fair enough in that case :D

  4. Sebastien Lambla Says:

    No, what’s evil is the VB extension methods, because you can pass the this pointer as a ref parameter. Now *thats* evil. :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: