Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The short type in C#

I am learning value types in C# and I noticed this:

when you hover over the value of a declared short, It says that It is a 32-bit int.
I know that a short is a 16-bit int.
Why isn’t It recognizing It as an int, or maybe It does?

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you are hovering over the value (32000) which is an int/System.Int32 literal. There isn’t a suffix for short to make a literal short. The compiler will do some gymnastics to ensure that it will fit. For instance, this should not compile.

int max = int.MaxValue;
short aShort = max;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading