Steven Giesel 4/1/2024

Pattern matching and the compiler can be surprising

Read Original

This technical article examines a specific C# pattern matching scenario where the compiler generates a CS8602 warning for dereferencing a possibly null reference, despite explicit null checks in the pattern. It analyzes the lowered IL code to explain the compiler's static analysis limitations and demonstrates a rare edge case that could lead to a NullReferenceException due to property side effects.

Pattern matching and the compiler can be surprising

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week