开发者

All math operations return as an integer? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

byte + byte = int… why?

I have a grid from (-1024,-1024) to (1024,1024), so I don't need all the values that an int provides, but I've noticed that all of my algorithms return as ints and I need to typecast them all with (short). Could anyone explain why all math operations return as int and is it more effective to parse as short since math operations return as int?

short yCoordinate = (short)(short.Pars开发者_运维技巧e(RtData[1][1]) - 1);


The return an int because most maths operations need larger numbers than a short can contain. The BCL is there for use by many programmers and the creators had to balance readability, usability and performance amongst others in order to create classed that are generally useful.

As method signatures do not take return type into account, they had to decided what would be most useful as a return type (short, int, long etc) for these functions. They decided that int was best.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜