chuawenching Posted August 3, 2003 Posted August 3, 2003 Hi there. I need some help here. I am trying to convert a sample application for learning purposes. But i am stuck to see this: Select Case ShipPitchSM Case Is > 0 ShipPitchSM = ShipPitchSM - Friction If ShipPitchSM < 0 Then ShipPitchSM = 0 If ShipPitchSM > 0.03 Then ShipPitchSM = 0.03 Case Is < 0 ShipPitchSM = ShipPitchSM + Friction If ShipPitchSM > 0 Then ShipPitchSM = 0 If ShipPitchSM < -0.03 Then ShipPitchSM = -0.03 End Select Select Case ShipYawSM Case Is > 0 ShipYawSM = ShipYawSM - Friction If ShipYawSM < 0 Then ShipYawSM = 0 If ShipYawSM > 0.03 Then ShipYawSM = 0.03 Case Is < 0 ShipYawSM = ShipYawSM + Friction If ShipYawSM > 0 Then ShipYawSM = 0 If ShipYawSM < -0.03 Then ShipYawSM = -0.03 End Select Select Case ShipRollSM Case Is > 0 ShipRollSM = ShipRollSM - Friction If ShipRollSM < 0 Then ShipRollSM = 0 If ShipRollSM > 0.03 Then ShipRollSM = 0.03 Case Is < 0 ShipRollSM = ShipRollSM + Friction If ShipRollSM > 0 Then ShipRollSM = 0 If ShipRollSM < -0.03 Then ShipRollSM = -0.03 End Select Any help? How do you code that in c#? I try my best to place conditions in case statements, but compile errors. Thanks. Regards, Chua Wen Ching :p Quote
wyrd Posted August 3, 2003 Posted August 3, 2003 I don't believe you can do that in C#. Just use a simple if statement, it'd be cleaner for what you're doing anyway; if (value > 0) { // Stuff... } else { // Less than 0. } Quote Gamer extraordinaire. Programmer wannabe.
chuawenching Posted August 3, 2003 Author Posted August 3, 2003 Thanks. Regards, Chua Wen Ching :p Quote
Leaders dynamic_sysop Posted August 3, 2003 Leaders Posted August 3, 2003 you could always use the switch statement , here's a simple example :) private void val() { int x =-1; switch(x.CompareTo(0)<0) { case true: MessageBox.Show("the value is less than zero!"); break; case false: MessageBox.Show("the value is greater than zero!"); break; } } Quote
*Experts* Volte Posted August 3, 2003 *Experts* Posted August 3, 2003 That's a pretty cheesy thing to do. :p Also, highly unnecesary, when this will do: if (x < 0) MessageBox.Show("the value is less than zero!"); else MessageBox.Show("the value is greater than zero!");Unless you are looking at the value of one variable, and comparing it to many others (3+ more), if statements are generally cleaner than switch statements. Quote
Leaders dynamic_sysop Posted August 3, 2003 Leaders Posted August 3, 2003 just proving a point that it can be done with switch ( he posted the same question on codeproject's forum and was basiclly under the impression that it wasn't possible with switch ) ;) i like to prove the impossible wrong , regardless how cheesey it may be:p Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.