我有一个object 如何得到它原来的类型???比如:
   object tempobj;
   byte[] Data;
   tempObj=Data;   if(tempObj 的类型是byte[])  //这里该怎么写???????????
   { 
      //说明是byte[],作相应处理      
    }
   else
   {
     //作其他处理
   }

解决方案 »

  1.   

    应该不能用object直接处理的
    要把他转化回来,试试强制转化
    如果强制转化不行的话,就只能自己写函数转了
      

  2.   

    if (tempObj.GetType() == typeof(byte))
      

  3.   

    object tempobj;
       byte[] Data = new byte[100];
       tempobj=Data;if (tempobj is byte[])

     byte[] x = (byte[])tempobj;  Console.WriteLine(x.Length);
    }orobject tempobj;
       byte[] Data = new byte[100];
       tempobj=Data;byte[] x = tempobj as byte[];if ( x != null)
    {
      Console.WriteLine(x.Length);
    }
      

  4.   

    generally, people doobject tempobj;
       byte[] Data = new byte[100];
       tempobj=Data;if (tempobj is byte[])

     byte[] x = (byte[])tempobj;  Console.WriteLine(x.Length);
    }orobject tempobj;
       byte[] Data = new byte[100];
       tempobj=Data;byte[] x = tempobj as byte[];if ( x != null)
    {
      Console.WriteLine(x.Length);
    }
      

  5.   

    object tempobj;
       byte[] Data;
       tempObj=Data;   if(tempObj.GetType() == (new byte[0]).GetType() )
       { 
          //说明是byte[],作相应处理      
        }
       else
       {
         //作其他处理
       }
      

  6.   

    object tempobj;
       byte[] Data;
       tempObj=Data;
       if((tempObj as byte[]) != null)
       { 
          //说明是byte[],作相应处理      
        }
       else
       {
         //作其他处理
       }
      

  7.   

    generally, people doobject tempobj;
       byte[] Data = new byte[100];
       tempobj=Data;if (tempobj is byte[])

     byte[] x = (byte[])tempobj;  Console.WriteLine(x.Length);
    }orobject tempobj;
       byte[] Data = new byte[100];
       tempobj=Data;byte[] x = tempobj as byte[];if ( x != null)
    {
      Console.WriteLine(x.Length);
    }generally, people doobject tempobj;
       byte[] Data = new byte[100];
       tempobj=Data;if (tempobj is byte[])

     byte[] x = (byte[])tempobj;  Console.WriteLine(x.Length);
    }orobject tempobj;
       byte[] Data = new byte[100];
       tempobj=Data;byte[] x = tempobj as byte[];if ( x != null)
    {
      Console.WriteLine(x.Length);
    }generally, people doobject tempobj;
       byte[] Data = new byte[100];
       tempobj=Data;if (tempobj is byte[])

     byte[] x = (byte[])tempobj;  Console.WriteLine(x.Length);
    }orobject tempobj;
       byte[] Data = new byte[100];
       tempobj=Data;byte[] x = tempobj as byte[];if ( x != null)
    {
      Console.WriteLine(x.Length);
    }
      

  8.   

    if (tempobj is byte[])

     byte[] x = (byte[])tempobj; }