我想进行以下判断:
        private string JudgeControl(Control ctl)
        {
            System.Type type = ctl.GetType();            switch (type)
            {
                case ?:
                    return "TextBox";
                    break;
                case ?:
                    return "ComboBox";
            }
        }“?”应该替换成什么才正确?

解决方案 »

  1.   

    System.windows.Form.TextBox 
    System.windows.Form.ComboBox
      

  2.   

    private string JudgeControl(Control ctl)
    {
      System.Type type = ctl.GetType();
      return type.Name;
    }
      

  3.   

    “System.Windows.Forms.TextBox”是一个“类型”,这在给定的上下文中无效另外貌似"switch"中放"type"也不对
    应输入整型值
      

  4.   

    switch 中放int 型或者string 型。
      

  5.   

    那就算我用"if","System.Windows.Forms.ComboBox"也不对啊if (ctl.GetType() == System.Windows.Forms.ComboBox)“System.Windows.Forms.ComboBox”是一个“类型”,这在给定的上下文中无效
      

  6.   


    这样写:
    if (ctl.GetType().ToString == "System.Windows.Forms.ComboBox")
      

  7.   

    或者:
    if(ctl.GetType() == typeof(System.Windows.Forms.ComboBox))