The programming language C# has many ways to check variables for a null value. Some are more intuitive than others. My team and I have run into confusion with checking nullable C# types so here are the major ways of checking for null values and then potential stumbling blocks with using the value after it has been checked.

Ways to Check for Null

There are two primary ways to compare variables to a null or empty value. C# has the equality operator and the is operator. They are similar but C#’s is primarily for checking if a variable is compatible with a given type. I will provide definitions for both and will use “is” for the example code because checking null is checking the type of a variable. Equality Operators

The …

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help