Silverlight 4.0 如何在linq查询中检查可为空的日期
我有一个employee类型的对象数组Silverlight 4.0 如何在linq查询中检查可为空的日期,silverlight-4.0,c#-4.0,Silverlight 4.0,C# 4.0,我有一个employee类型的对象数组 var s = from x in employee where !string.IsNullOrEmpty(x.FirstName) && (x.FirstName.IndexOf(searchText, StringComparison.OrdinalIgnoreCase)) >= 0 || !string.IsNullOrEmpty(x.LastName) &
var s = from x in employee
where !string.IsNullOrEmpty(x.FirstName) && (x.FirstName.IndexOf(searchText, StringComparison.OrdinalIgnoreCase)) >= 0 || !string.IsNullOrEmpty(x.LastName) && (x.LastName.IndexOf(searchText, StringComparison.OrdinalIgnoreCase)) >= 0 ||
//I want to check here for null DateOfBirth
x.DateOfBirth.Value.ToShortDateString().StartsWith(searchText, StringComparison.OrdinalIgnoreCase)
select x;
我想你只需要
&& x.DateOfBirth.HasValue &&
添加到where子句中以过滤掉空的DOB
我假设DateOfBirth是一个可为空的DateTime