저장되는 다양한 Phone을 설명하는 클래스가 있습니다. 때때로 Importance
속성은 null 일 수 있습니다. 여기에 내가 전화 번호와 계좌 번호가 지정된 값 세트와 일치하는 경우 PhoneTypeListInfo
를 반환하는 함수를 정의하는 클래스Nullable 형식이며 .HasValue는 여전히 Null 예외를 throw합니다.
public class PhoneTypeListInfo
{
public string AccountNum { get; set; }
public int PhoneType { get; set; }
public string PhoneNum { get; set; }
public int Importance { get; set; }
}
입니다.
protected PhoneTypeListInfo RetrievePhoneType(string info, string acctNumber)
{
PhoneTypeListInfo type = xPhoneTypeList.Where(p => p.PhoneNum == info && p.AccountNum == acctNumber).FirstOrDefault();
return type;
}
이 모두 잘 작동합니다. 내가 겪고있는 문제는 아래 linq 쿼리입니다. PhoneTypeListInfo에서 '중요성'속성을 얻기를 제외하고, 다른 성분을 가진 다른 클래스를 사용하려고 내가 위에서 뭐하는 거지
List<AlertBasedPhones> xAccountPhones = new List<AlertBasedPhones>();
xAccountPhones = (from x in xAccountStuff
where x.Media == "Phone"
let p = RetrievePhoneType(x.Info, acct.AccountNumber)
let xyz = x.Importance = (p.Importance as int?).HasValue ? p.Importance : 0
orderby p.Importance descending
select x).ToList();
.
내 질문에 궁극적으로는 p.Importance
이 null이되게하려면 무엇을해야하며, null이면 0으로 설정하여 x.Importance
도 0으로 만듭니다.
나는'p.Importannce'는 null이 아니라'p' 자체라고 생각하지 않습니다. –
Scott이 맞다고 생각합니다.'RetrievePhoneType'이 null을 반환 할 수 있기 때문에 p 자체에 대한 추가 점검이 필요합니다. –
null 프로 그래 게이트 연산자? 여기서 유용 할 수 있습니다. –