0

Which method it is called on 3.ToString()?

  1. System.Int16.ToString()
  2. System.Int32.ToString()
  3. System.Int64.ToString()
Mark
  • 1,100
  • 9
  • 17
  • 7
    You could answer this yourself by checking what `3.GetType()` returns – Paul Phillips Jun 15 '12 at 16:20
  • 1
    have a look at this question : http://stackoverflow.com/questions/9696660/what-is-the-difference-between-int-int16-int32-int64 – huMpty duMpty Jun 15 '12 at 16:20
  • To whomever is closing this as "not constructive" and "not a real question" -- I think you all need to reassess what those close reasons are for. The only reasonable ones might be "too localized" (common knowledge) or because it's a dup. – Kirk Woll Jun 15 '12 at 16:33

2 Answers2

6

All integer literals in C# default to int (Int32) unless they are too big for int, in which case they become a larger data type that fits, like long(Int64).

So in this case, Int32.ToString() is called.

Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
  • Thanks for the answer but reading your solution made me realize that first it tries Int32 than UInt32, than Int64 and then UInt64. – Mark Jun 15 '12 at 16:36
1

System.Int32.ToString() as literal integers are Int32 type

undefined
  • 1,354
  • 1
  • 8
  • 19
  • 4
    This is true is this particular case, but note that if the literal exceeds the capacity of an `int`, it will be promoted to a `long`. – Frédéric Hamidi Jun 15 '12 at 16:21