int? ??


Can someone help me make sense of the following  c# code, please?

int myint = myvar as int? ?? 0;
Who is Participating?
p_davisConnect With a Mentor Commented:
int myint = myvar as int? ?? 0;

int? is a nullable variable the ?? checks for null and if it is the value returned is 0
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
It means if myvar is null then it is converted to zero when assigned to myint
(if myvar is null then myint = 0)
sdc248Author Commented:
Thanks, guys.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.