This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hello, this is about a conversion from int to byte and int to double. Why does iftest1a work and iftest1b doesn’t? What must be done to get iftest1b to work properly?
Compiles and runs with result: „i < a“ [ edited to preserve formatting using the [code] and [/code] UBB tags -ds ] [ July 24, 2002: Message edited by: Dirk Schreckmann ]
Neil Laurance
Ranch Hand
Joined: Jul 18, 2002
Posts: 183
posted
0
Primitives can be automatically converted if the new primitive is 'wider'. So the following is possible: int (32 bits) -> double (64 bits) However, you cannot automatically convert to a narrower primitive. This is not possible: int (32 bits) -> byte (8 bits) To do this, you must use an explicit cast expression: int i = 3; byte b = (byte)i; Cheers, Neil [ July 24, 2002: Message edited by: Neil Laurance ]