I have the following in my model:
public string Subject {
get {
return SubjectReference.GetSubject(SubjectID);
}
}
How can I make this so that if the SubjectID is null then the get call will return null? I think there’s a way to do this with the ? operator but can I use this inside of a class for model properties?
How about
You could consider
string.IsNullOrEmpty(SubjectID)instead when an empty string forSubjectIDshould also result in anullreturn.If your property is a reference type then of course
nullis a legal return value.