using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Example24
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            object P_obj = radioButton1.Checked ?   // 正确地为变量添加引用
                (object)"C# 编程词典" : new System.IO.FileInfo(@"d:\"); //@除去转义字符效果
            if (radioButton4.Checked)           //判断选择了哪一个类型
            {
                if (P_obj is System.String)     //判断是否字符串类型
                {
                    MessageBox.Show("对象与指定类型兼容", "提示");  //提示兼容信息
                }
                else
                {
                    MessageBox.Show("对象与指定类型不兼容", "提示"); //提示不兼容信息
                }
            }
            else
            {
                if (P_obj is System.IO.FileInfo)
                {
                    MessageBox.Show("对象与指定类型兼容", "提示");  //提示兼容信息
                }
                else
                {
                    MessageBox.Show("对象与指定类型不兼容", "提示"); //提示不兼容信息
                }
            }
        }
    }
}
posted on 2011-10-17 01:32  C#_初学者  阅读(273)  评论(0编辑  收藏  举报