1 Replies - 311 Views - Last Post: 05 October 2011 - 08:42 PM Rate Topic: -----

#1 anitdragon13   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon

Reputation: 5106
  • View blog
  • 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".
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1