Using Int32.Parse

Why is it necessary to convert a value (for example, short) to a string, and then to Int32. Why can't it be converted from short to int 32?

+3
source share
2 answers

There is no need even for any explicit conversion:

short s = 23;
int k = s;

In addition, any numeric literals (without any suffixes) are int32 anyway.

- Change

The reason for the explicit cast is not required, since a is shortalways smaller than int, therefore shortit will always fit completely into the size int, therefore potential data loss.

+8
source

You do not need this because you can use:

short shortNumber = 11;
int notAsShortNumber = (int)shortNumber;
+4

Source: https://habr.com/ru/post/1716647/


All Articles