shahine.com/omar/

homepage | Send mail to the author(s) contact

yet another Microsoft blogger

# Friday, March 26, 2004

is keyword

I don't know how I missed the is keyword in C#. I must have been asleep or something when I read about this. Up till now I've been getting the type of an object and comparing to the typeof() a class.

object foo = "bar";

if (foo is string)
{
    Console.WriteLine("foo is a string");
}

if (foo.GetType() == typeof(string))
{
    Console.WriteLine("foo is a string");
}

 

Friday, March 26, 2004 11:52:07 AM (Pacific Daylight Time, UTC-07:00)
Careful! The "is" keyword returns if the object *can be cast* to the specified type. OTOH, "==" is implemented by Type.Equals, which tests to see if both types are the *same*.
Friday, March 26, 2004 4:13:03 PM (Pacific Daylight Time, UTC-07:00)
python!
pbox
Tuesday, April 26, 2005 11:39:18 AM (Pacific Daylight Time, UTC-07:00)
Do you all know the negation of "is" in C#?
Chris Stewart
Comments are closed.