Re: c# interview question



Peter

You could argue they're testing the depth of knowledge by asking the
question, but I do agree, I wouldn't like to work for a company that
constantly questioned my choice of string concatenation technique.

Glenn

"Peter Bradley" <pbradley@xxxxxxxxxx> wrote in message
news:%23iXnH1IZHHA.4940@xxxxxxxxxxxxxxxxxxxxxxx
My guess - and it is just a guess - is that the implicit cast probably
uses the ToString() method anyway. I would have thought any difference
between the two would have been optimized away by the compiler, but what
do I know?

One thing's for sure, if you (or rather your prospective employers) need
to worry about performance at this level, then they're using the wrong
language. To me, it's on a par with worrying about whether:

i++;

is more efficient than:

++i;

Who cares. If you're writing code where these differences are
significant, use C or C++, or even Assembly language.

Just my 2c. YMMV.


Peter

"Steve Bugden" <SteveBugden@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:606BB626-8DDC-40CD-87F7-7A9B00608284@xxxxxxxxxxxxxxxx
Hi,

I recently had an interview where I was asked a number of questions on
C#.
Unfortunately I didn't get the answers from the test and find that one of
them is still niggling me.

It was something like this:

Consider the following code:

int i = 0;
Console.WriteLine("The value is: " + i);
Console.WriteLine("The value is: " + i.ToString());

Which would you use to write an integer to the console and why would it
give
better performance?

I said I would use: Console.WriteLine("The value is: " +
i.ToString());

But I can't think why this should give a performance advantage. I can
only
guess that the compiler should be able to realise that a string is
required
from the integer for the line not using the ToString() method and
generate
the same MSIL.

Can anyone please enlighten me?

Best Regards,

Steve




.



Relevant Pages

  • Re: c# interview question
    ... the ToString() method anyway. ... the two would have been optimized away by the compiler, ... If you're writing code where these differences are significant, ... use C or C++, or even Assembly language. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ALDS cross-assembler and linker available
    ... linked with a linker to make an executable file, or the assembler output ... language was that there were no system "libraries" to link against. ... the assembly language to do the same thing for the ... If you had the Misosys C compiler, ...
    (comp.sys.tandy)
  • Re: The history of Structure capabilities
    ... macro in assembly language that would allow it to act roughly like the ... to include even one byte of overhead not actually needed by the routine ... The compiler doesn't necessarily have to include anything that you ... memory, or that runs even one-quarter as fast. ...
    (comp.lang.asm.x86)
  • Re: What is the licensing status of Fig-Forth v 2.32? Are Forth compilers generally safe?
    ... This is a shareware compiler, and the notes say that one is ... permanently damage your computer. ... Normally this means assembly language. ... big difference between the 1980's and now is the documentation. ...
    (comp.lang.forth)
  • Re: Interesting article by Randall Hyde
    ... as you are the compiler optimization "expert". ... of the work that has gone into creating optimizing compilers. ... > Compilers generate better code than *most* programmers all of the ... learn without needing to know anything about assembly language. ...
    (comp.lang.asm.x86)

Loading