Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# question mark operator postfixed to cast

Tags:

operators

c#

I was looking at the dapper page and saw this terse bit of coding:

   new { Age = (int?)null, Id = guid });

What does (int?)null do?

Could someone please elucidate what is going on there, and perhaps give a more "verbose" version of the code?

like image 761
Tim Avatar asked May 26 '26 04:05

Tim


1 Answers

int? is shorthand for Nullable<int>. as such this line of code is converting null (which by default is of type object) to a null int.

Docs: http://msdn.microsoft.com/en-us/library/b3h38hb0.aspx

like image 196
Jamiec Avatar answered May 30 '26 14:05

Jamiec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!