How to make a IsNull() method

c#, isnull

Solution

You're missing the `this` modifier to make it a true extension method as well as making the object static.

public static class ObjectExtensions
{
    public static bool IsNull(this object obj)
    {
        return obj == null;
    }
}

Then you can call it like so:

var fooIsNull = foo.IsNull();
// which is syntactic sugar for
fooIsNull = ObjectExtensions.IsNull(foo);

Problem

I'm trying to make a method similar to .ToString() that checks whether the object is null or not. I just done know how to make it accessible without calling the class ``` public class ObjectExtensions { public static bool IsNull(object obj) { bool val = false; if (obj == null) { val = true; } return val; } } ```

Original source