Alex Rivera | Logout

Why null string is not a string object

Asked 2013-07-08T12:43:19.883
8

Consider this code:

  class Program
        {
            static void Main(string[] args)
            {

                string s = null; 
                bool b = s is string;
                Console.WriteLine(b);
            }
        }

In above code s is string but b is false.

actually s as string,Why i get this result ?

Why compiler has this behavior?

Edit
Report

1 Answer

0

The null keyword is a literal that represents a null reference, one that does not refer to any object.

http://msdn.microsoft.com/en-us/library/edakx9da.aspx

s is string is false because s does not reference an instance of string - s is null.

answered 2013-07-08T12:46:19.880

Your Answer