Ayende @ Rahien

Unnatural acts on source code

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);

Comments

Robert
05/09/2010 09:23 AM by
Robert

Int64 (or long) - there's no difference in current version of CLR

Anon
05/09/2010 10:04 AM by
Anon

short?

Hadi Eskandari
05/09/2010 10:26 AM by
Hadi Eskandari

As Robert said, it would be long.

tobi
05/09/2010 12:18 PM by
tobi

I do not see the riddle here...

Ayende Rahien
05/09/2010 12:41 PM by
Ayende Rahien

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).

Stefan Wenig
05/09/2010 01:44 PM by
Stefan Wenig

only if you remove the extra semicolon. sorry, I was just nitpicking.

Diego Mijelshon
05/09/2010 01:47 PM by
Diego Mijelshon

It's long; the second part of the expression is automatically converted, which makes the conditional unnecessary.

Marc Gravell
05/10/2010 12:39 PM by
Marc Gravell

there's no difference in current version of CLR

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...

Comments have been closed on this topic.