私はこのルーチンを持っている:なぜNull Coalesce演算子はnullを返すのですか?
try
{
CurrentSessionName = SelectedSession?.Name ?? "No Session Selected";
CurrentSessionTolerance = SelectedSession?.Tolerance.ToString() ?? "N/A";
CurrentSessionVerification = SelectedSession?.Verification.Description ?? "N/A";
}
catch (Exception ex)
{
var whatever = ex.GetType(); // hits here with no provided information
Console.WriteLine("Null Reference Exception"); // ignores this
string name = SelectedSession?.Name; // and this
}
、なぜそれはまだSelectedSession
がNullでない場合であってもNullReferenceException
エラーをスローしますか?
に
ToString()
を呼び出そうと、その後のですか?また、 'SelectedSession.Tolerance'と' SelectedSession.Verification'はnullでもかまいません。 –よく 'SelectedSession'はあなたがそれからのヌル伝道を使っているので、投げません。 'SelectedSession.Tolerance'や' SelectedSession.Verification'はどうでしょうか? – Jonesopolis
完全なエラー+スタックトレースを投稿してください。 – sstan