如果判断一个object对象是否为bool型
请给出示例代码,谢谢

解决方案 »

  1.   

    object o = false;
    Text = (o is bool).ToString();好像is可以判断
      

  2.   

      object o = "ad";
            Response.Write(o.GetType());
      

  3.   


     Dim o As Object = False
            If TypeOf o Is Boolean Then
            End If
      

  4.   


    object o = ...;
    bool isBool = (o is bool);
      

  5.   

    或者:
    object o = true;bool isBool = (o.GetType() == typeof(bool));Console.WriteLine(isBool.ToString());
      

  6.   

    object obj = true;if (obj is bool)
    {
        Console.WriteLine("是Bool")
    }
    else
    {
        Console.WriteLine("不是Bool")
    }
      

  7.   

    object o = false ;
            bool   result=o is bool;
            if (result == true)
            {
                Response.Write("是 bool类型!");
            }