Riddle me this? What is the type?
What is the static type of the following expression?
number.Length == 18 ? Convert.ToInt64(number, 16) : Convert.ToInt32(number, 16);
What is the static type of the following expression?
number.Length == 18 ? Convert.ToInt64(number, 16) : Convert.ToInt32(number, 16);
And 4 more posts are pending...
There are posts all the way to Feb 17, 2025
Comments
Int64 (or long) - there's no difference in current version of CLR
short?
As Robert said, it would be long.
I do not see the riddle here...
Stefan,
This is an expression.
As a proof of that, you can put that thing in a 3.5 linq expression (which doesn't support statements).
only if you remove the extra semicolon. sorry, I was just nitpicking.
It's long; the second part of the expression is automatically converted, which makes the conditional unnecessary.
That would be a boolean.
Since an implicit conversion exists from int32 to int64 and not vice versa, the type of this expression is int64. See the C# spec:
http://msdn.microsoft.com/en-us/library/aa691313(VS.71).aspx
Nevermind, I must've been drunk.
Just a pedantic point; the CLR doesn't get to choose here - it is the language that defines both the "long" keyword and the conversion rules that it chooses to follow (and how to implement them). And "long" is /defined/ as an alias to global::System.Int64, so we should be OK for the time being...
Comment preview