-1

Jon Skeet, has an interesting post titled: "Why boxing doesn't keep me awake at night" where he benchmarks the performance of different ways of outputting an integer value.

I am pretty sure the code below IS boxing, but why Jon is considering it NOT to be boxing? his example is at the end.

int i = 5;
object o = i;
Console.WriteLine("Number is: {0}", o);

The example from Jon's page:

#if CONSOLE_WITH_BOXING
            Console.WriteLine("{0} {1} {2}", i, i, i);            
#elif CONSOLE_NO_BOXING
            object o = i;
            Console.WriteLine("{0} {1} {2}", o, o, o);
#elif CONSOLE_STRINGS
            string s = i.ToString();
            Console.WriteLine("{0} {1} {2}", s, s, s);

P.S. "boxing and unboxing in int and string" does not answer my question.

Thank you.

Community
  • 1
  • 1
MaYaN
  • 6,683
  • 12
  • 57
  • 109
  • Did you just deleted your previous question and reported? – Patrick Hofman Jul 23 '14 at 11:42
  • Yes I did, as it was marked as DUPLICATE, so instead of editting I removed it and posted a new one. – MaYaN Jul 23 '14 at 11:44
  • possible duplicate of [boxing and unboxing in int and string](http://stackoverflow.com/questions/6423452/boxing-and-unboxing-in-int-and-string) – Patrick Hofman Jul 23 '14 at 11:45
  • Don't repost. Just tell in the original post why you think it isn't a duplicate. – Patrick Hofman Jul 23 '14 at 11:46
  • @Patrick SO recommends to edit or ask a new question when a question is flagged as duplicate also the "boxing and unboxing in int and string" does not answer my question as mentioned above. :-) – MaYaN Jul 23 '14 at 11:46
  • I am pretty sure that is not the case. A post can be reopened if it isn't a duplicate. – Patrick Hofman Jul 23 '14 at 11:48
  • @Patrick, I didn't say it can't be reopened/edited, asking a new question is one of the 2 options available which is what I chose. I think it is better to concentrate on the question/answer instead of going on a tangent here – MaYaN Jul 23 '14 at 11:50
  • No. You should not repost. Can you supply a link to meta whether reposting is allowed? – Patrick Hofman Jul 23 '14 at 11:55
  • 2
    So let me get this straight: you deleted a question to protest it being marked as a duplicate, then proceeded to repost it? Doesn't that make your reposted question a duplicate of itself? Talk about a self-fulfilling prophecy. – BoltClock Jul 23 '14 at 11:58
  • Without getting too Meta here, it says new question, not the same question again – Klors Jul 23 '14 at 12:00
  • @Klors this question is not the "same question" it is a new one which now has an answer! :-) – MaYaN Jul 23 '14 at 12:01
  • @MaYaN: It... is the same question. A new *copy*, but the same question. The fact that it now has an answer is irrelevant. In any case, please don't do this again. It's not allowed, and will only serve to increase your chances of getting banned from asking questions altogether. – BoltClock Jul 23 '14 at 12:04
  • @BoltClock, you may be right! now let's move on :-) – MaYaN Jul 23 '14 at 12:05

1 Answers1

2

It is boxing, the only difference is on what line it is happening:

not boxing (see http://msdn.microsoft.com/en-us/library/a0bfz20d%28v=vs.110%29.aspx):

Console.WriteLine("{0} {1} {2}", o, o, o);

boxing:

object o = i;

or consider

three boxing(s):

Console.WriteLine("{0} {1} {2}", i, i, i);

one boxing:

object o = i;
Console.WriteLine("{0} {1} {2}", o, o, o);
mikey
  • 5,090
  • 3
  • 24
  • 27