Lookup the "AS" keyword. Example stright out of MSDN.
public static void Main()
{
object [] myObjects = new object[6];
myObjects[0] = new MyClass1();
myObjects[1] = new MyClass2();
myObjects[2] = "hello";
myObjects[3] = 123;
myObjects[4] = 123.4;
myObjects[5] = null;
for (int i = 0; i < myObjects.Length; ++i)
{
string s = myObjects[i] as string;
Console.Write ("{0}:", i);
if (s != null)
Console.WriteLine ( "'" + s + "'" );
else
Console.WriteLine ( "not a string" );
}
}
}
Jason Newell, MCAD
Software Engineer
MM wrote:
Very basic question:
string mystr
how do you test if it is a string?
Something like
if (mystr.GetType() == "System.String") <<< but this doesn't work.
Thanks for pointing me in the right direction.