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" ); } } } 输出 0:not a string 1:not a string 2:''''hello'''' 3:not a string 4:not a string 5:not a string 14.new 操作符 new操作符用于创建一个新的类型实例,有三种形式: A:对象创建表达式,用于创建一个类类型或值类型的实例。 B:数组创建表达式,用于创建一个数组类型实例。 C:委托创建表达式,用于创建一个新的委托类型实例。 15.typeof操作符 typeof操作符用于获得系统原型对象的类型。 using System; class MikeCat { public static void Main() { Console.WriteLine(typeof(int)); Console.WriteLine(typeof(System.Int32)); } }//结果:System.Int32 System.Int32 //表明int和System.Int32是同一个类型 c#中用GetType()方法获得一个表达式在运行时的类型 using System; class MikeCat { 上一页 [1] [2] [3] [4] 下一页 |