expression as type
expression is type? (type)expression : (type)null
// keyword as using System; class CSharpFriends { // empty } class ASPDotNet { // empty } public class Test { public static void Main() { object[] myObjects = new object[5]; myObjects[0] = new CSharpFriends(); myObjects[1] = new ASPDotNet(); myObjects[2] = "C# is fun!"; myObjects[3] = 2002; myObjects[4] = 99.99; // the lowest price is the law! for(int i = 0; i < myObjects.Length; i++) { string s = myObjects[i] as string; Console.Write("myObject[{i}]", i); if (s != null) { Console.WriteLine (" is "); } else { Console.WriteLine ("not a string"); } } // pause console window Console.ReadLine(); } }
Build Your Own ASP.NET Website Using C# & VB.NET