我正在使用对象类型变量来存储查询结果以绑定到下拉列表。如果是,我不想对对象进行进一步处理null
。
我的代码是:
object course;
if (GetWebsiteCurrentMode().ToLower() == "demo")
{
course = from t in context.CourseTestDetails
join c in context.Courses
on t.CourseID equals c.ID
where t.UserID == UserID && c.IsDeleted == true
select new
{
c.ID,
c.CourseName
};
}
else
{
course = from t in context.CourseTestDetails
join c in context.Courses
on t.CourseID equals c.ID
where t.UserID == UserID c.IsDeleted == false
select new
{
c.ID,
c.CourseName
}
}
if(course !=null )
{
ddlCourseName.DataSource = course;
ddlCourseName.DataBind();
ddlCourseName.Items.Insert(0, new ListItem("Select Course Name", "0"));
ddlCourseName.SelectedValue = "0";
}
else
{
//do something different
}
如何检查对象类型变量是否为空/空?