这里要说明一下,在C#中不存在未知类型这样的说法因为,任何类型都要确保是在托管环境下的安全,你在定义变量的时候必须指明变量的类型.

解决方案 »

  1.   

    不错你使用的时候就要初始化
      

  2.   

    The following sample shows how variables of type object can accept values of any data type and how variables of type object can use methods on System.Object from the .NET Framework.// keyword_object.cs
    using System;
    public class MyClass1 
    {
       public int i = 10;
    }public class MyClass2 
    {
       public static void Main() 
       {
          object a;
          a = 1;   // an example of boxing
          Console.WriteLine(a);
          Console.WriteLine(a.GetType());
          Console.WriteLine(a.ToString());
          Console.WriteLine();      a = new MyClass1 ();
          MyClass1 ref_MyClass1;
          ref_MyClass1 = (MyClass1)a;
          Console.WriteLine(ref_MyClass1.i);
       }
    }