Dividing sbyte typed variables

K

K Viltersten

I try the following.

sbyte HalvOfFour () {
sbyte b = 4;
return b / 2;
}

Apparently, since 2 is regarded as int, the operation
upgrades my b to and int and after it has been
performed, i stand there with an int, which is wrong
type to return.

What i've done about it was to cast the division to a
string by adding an empty string, then parsing it
using the default parser SByte.parse (string).

It works but it sure looks ugly. Any hints?
 
K

K Viltersten

Den 2008-06-04 12:09:19 skrev Paul E Collins
Oof. Don't do that. Try casting the result: (sbyte) (b / 2)

Ah, yes. I forgot the parenteses and type casted only b,
i'm guessing. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top