Làm cách nào để tính năm trong ngày nullable
?Năm trong Thời gian rảnh rỗi
partial void AgeAtDiagnosis_Compute(ref int result)
{
// Set result to the desired field value
result = DateofDiagnosis.Year - DateofBirth.Year;
if (DateofBirth > DateofDiagnosis.AddYears(-result))
{
result--;
}
}
Lỗi này là:
'System.Nullable<System.DateTime>' does not contain a definition for 'Year' and no
extension method 'Year' accepting a first argument of
type 'System.Nullable<System.DateTime>' could be found (are you missing a using
directive or an assembly reference?)
Liệu nó làm việc với DateTime thật không? Nếu vậy bạn không thể sử dụng giá trị không null. Có vẻ như nếu nó không phải là tính toán năm là không cần thiết anyway? – TGH
Bạn nên tìm kiếm trên google https://www.google.co.in/search?q=nullable+datetime+in+c%23 – Prakash