私は、格納されているさまざまな電話を記述するクラスを持っています。場合によってはImportance
プロパティをnullにすることもできます。ここで私は電話番号と口座番号が値のセットと一致する場合PhoneTypeListInfo
を返す関数を定義したクラスnullの型と.HasValueはまだNull例外をスローします
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'がヌルを返すことができるので、あなたはp自身のために余分なチェックを必要とします –
null progagating operator?ここで役に立つかもしれない。 –