Link to home
Start Free TrialLog in
Avatar of pzozulka
pzozulka

asked on

C#: Integer Types

I'm reading the Wrox book: C# 2012 and .NET 4.5. It says:
If there is any ambiguity about whether an intege ris int, uint, long, or ulong, it will default to an int. To specify which of the other integer types the value should take, you can append a character such as "L" to the end of the number. For example:
long l = 10L;
I'm confused.

What if I did something like this:

long l = 20;

Although 20 looks like small int or maybe a regular int, wouldn't there be some kind of implicit type conversion so that the variable "l" would store a long? Why is there a need to append the "L" character?
Avatar of pzozulka
pzozulka

ASKER

Similarly with decimals vs. floats.

If you hard-code a non-int number (such as 12.3), the compiler will normally assume that you want the number interpreted as a double. If you want to specify the number as a float, you should append an "F".

float myFloat = 12.3;

Again same question, fine 12.3 is interpreted as a double, but when it is assigned to myFloat, should there be some kind of implicit type conversion happening to convert that decimal number into a float? If not, what will be the result of the above line of code?
ASKER CERTIFIED SOLUTION
Avatar of Naman Goel
Naman Goel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial