Per Erik Strandberg /cv /kurser /blog

I never quite remember how to treat null - so by writing this I hope I'll always remember.

using System;

namespace myNullTester
{
    class Program
    {
        class myClass { }

        static void Main(string[] args)
        {
            myClass a = new myClass();
            myClass b = a;
            a = null;

            if (a == null) Console.WriteLine("a is null");
            if (b == null) Console.WriteLine("b is null");
        }
    }
}

The output is, of course, a is null.


Tillhör Kategori Programmering