Jak mogę obliczyć rok w nullable
datę?Rok w Nullable DateTime
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--;
}
}
Błąd jest:
'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?)
Czy to działa z prawdziwym DateTime? Jeśli tak, nie możesz użyć wartości niepustej. Wydaje się, że jeśli jest zerowa, obliczenia roku i tak nie są potrzebne? – TGH
Powinieneś wyszukiwać google https://www.google.co.in/search?q=nullable+datetime+w+c%23 – Prakash