# question: short variable

Page 1 of 1

## 1 Replies - 311 Views - Last Post: 05 October 2011 - 08:42 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=250068&amp;s=2536886d96037fc01541744e1b436bb5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 anitdragon13

Reputation: 0
• Posts: 28
• Joined: 05-October 11

# question: short variable

Posted 05 October 2011 - 08:14 PM

what does (short) do and mean in (short)((x + 1) + y * WIDTH) in c#
im thinking that it changes the final integer into a short variable, but im not sure. i would look it up, im not sure what this is called. thank you
Is This A Good Question/Topic? 0

## Replies To: question: short variable

### #2 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5106
• Posts: 9,283
• Joined: 08-June 10

## Re: question: short variable

Posted 05 October 2011 - 08:42 PM

First, some definitions. An int is a 32-bit signed integer. That means that it can hold both positive and negative values, and it takes up 32 bits of space in memory. A short is a 16-bit signed integer. Similar, with the difference being the size in memory. Their sizes also determine their minimum and maximum values.

Integar literals (when you just type a number) are by default, ints, and so is the result of math done with them. If, however, you want to store this value in a smaller space, you can cast it to a short. That's what (short) does. It converts an int value into a short value.

You can do this with any compatible types that have defined explicit casts, which ints and shorts have.

You can usually find this kind of information by searching "C# short" or "MSDN short".