Tina,
It's not incorrect, but rather, it is the way that C# is supposed to
work.
When you divide two integers by each other in C#, it will produce the
integer result. Any remainder is going to be dropped.
In this case, 0 is produced. Then, it is cast to a double, producing
0.0.
If you want to get the result of .75, then one of the operands has to be
a floating type (single, double). You would have to do this:
myAspectRatio = (float) myWidth / myHeight;
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Tina" <ti**********@nospammeexcite.com> wrote in message
news:ul****************@TK2MSFTNGP04.phx.gbl...
This C# code produces a value of 0.0 in myAspectRatio....
int myWidth = 1200;
int myHeight = 1600;
double myAspectRatio = 0.0;
myAspectRatio = myWidth / myHeight;
This VB code produces a value of .75 (the correct answer) in
myAspectRatio..
Dim myWidth As Integer = 1200
Dim myHeight As Integer = 1600
Dim myAspectRatio As Double = 0.0
myAspectRatio = myWidth / myHeight
Why does the C# code produce the incorrect answer of 0.0?
Thanks,
T