C#Equal的使用

来源:互联网 发布:java 支付宝沙箱测试 编辑:程序博客网 时间:2024/05/03 14:58
代码如下:
 public partial class FramMain : Form    {        public FramMain()        {            InitializeComponent();        }        private void btnCheckedEqual_Click(object sender, EventArgs e)        {            object p = ckbObjectString.Checked ? (object)"C#编程词典" : new System.IO.FileInfo(@"d:\");                //正确地为变量添加引用            if (ckbTypeofString.Checked)                                                                               //判断选择了哪一个类型            {                if (p is System.String)                                                                                //判断对象是否为字符串类型                                 MessageBox.Show("对象与指定类型兼容","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);      //提示兼容消息                else                    MessageBox.Show("对象与指定类型不兼容", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);  //提示不兼容消息              }            else            {                if (p is System.IO.FileInfo)                                                                            //判断对象是否为文件类型                                 MessageBox.Show("对象与指定类型兼容","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);       //提示兼容消息                else                    MessageBox.Show("对象与指定类型不兼容", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);  //提示不兼容消息            }        }    }


1 0
原创粉丝点击