日期:2014-05-18 浏览次数:20805 次
public partial class CSDN_Code_1 : System.Web.UI.Page { public string typeHmtl = string.Empty; public string typeHmtl_1 = string.Empty; object data_type = new object(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Random rd = new Random(); if (rd.Next(100) % 2 == 0) { data_type = new DataTable(); } else { data_type = new List<string>(); } // 第1种方式判断 if (data_type is DataTable) { typeHmtl = "DataTable"; } else { typeHmtl = "List<string>"; } // 第二种方式判断 Type type=data_type.GetType(); if (type == typeof(DataTable)) { typeHmtl_1 = "DataTable"; } else { typeHmtl_1 = "List<string>"; } } } }