473,811 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# interview question

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.WriteLi ne("The value is: " + i);
Console.WriteLi ne("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.WriteLi ne("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
Mar 12 '07
34 2588
On 13 Mar, 16:05, "Mike Schilling" <a...@newsgroup .nospamwrote:
DeveloperX wrote:
time. Just an example.
Oh well as I said, The entire thread went off topic, my original
intention was to show the different operation of the two lines, I
didn't expect to be called an idiot for trying to explain how
something works, so apologies if I came across as overly defensive.

I wasn't calling you an idiot, but the interviewer, for

1. Considering this bit of trivia important, and
2. Expecting the OP to know it off the top of his head.

I disagree with you that there's clearly a performance issue here; there's
no way of telling that without knowing what the JIT output looks like, but I
wouldn't insult you over that.
Ah well that's ok then, sorry for the misunderstandin g, I felt quite
annoyed at the time. I understand the context of your performance
comments and basically agree. In reality I'd be profiling the
application looking for tweaks and bottlenecks as opposed to
disassembling it and pouring over the IL, although there's every
possibility I'd apply such a tiny change if I thought the benefit was
there.

Well, I've picked up some interesting tidbits along the way, so it's
not all lost, so cheers guys and onward :)

Mar 13 '07 #31
Mike Schilling wrote:
DeveloperX wrote:
>time. Just an example.

Oh well as I said, The entire thread went off topic, my original
intention was to show the different operation of the two lines, I
didn't expect to be called an idiot for trying to explain how
something works, so apologies if I came across as overly defensive.

I wasn't calling you an idiot, but the interviewer
Actually you were clearly referring to the other posters in the thread,
not the interviewer, when you state the criteria for being an idiot.
Claiming that everyone who don't share your opionions are idiots, is not
the best way of entering a debate. I can understand if people get upset
by that.
>, for

1. Considering this bit of trivia important, and
That is only your opinion, and not sharing it is no reason to suspect a
lack of intellectual capacity.
2. Expecting the OP to know it off the top of his head.
I wouldn't expect anyone to know the answers to every question in an
interview. Then the questions are too easy, or the applicant overqualified.

I would however consider the answer that there is no difference between
the lines to be worse than admitting that you don't know the difference.
I disagree with you that there's clearly a performance issue here;
The given code clearly has no performance problems, but it demonstrates
boxing, which clearly can cause performance problems.
there's
no way of telling that without knowing what the JIT output looks like,
Sure there is. Examining the IL code works just as well.
but I
wouldn't insult you over that.
--
Göran Andersson
_____
http://www.guffa.com
Mar 13 '07 #32

Q) Do you use C#
A) Don't hire anyone that says YES; because VB is an obviously
superior langauge with greater code portability

On Mar 12, 2:39 am, Steve Bugden
<SteveBug...@di scussions.micro soft.comwrote:
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.WriteLi ne("The value is: " + i);
Console.WriteLi ne("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.WriteLi ne("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

Mar 13 '07 #33
int i = 0;
//This will use implicit conversion
Console.WriteLi ne("The value is: " + i);
//This will not use implcit conversion as we already declared ToString()
so Performance will be fast.
Console.WriteLi ne("The value is: " + i.ToString());
Console.Read();

Nitin Sharma
(Guru .Net)

*** Sent via Developersdex http://www.developersdex.com ***
Mar 14 '07 #34
On Mar 14, 7:13 am, Nitin Sharma <loinni...@gmai l.comwrote:
int i = 0;
//This will use implicit conversion
Console.WriteLi ne("The value is: " + i);
//This will not use implcit conversion as we already declared ToString()
so Performance will be fast.
Console.WriteLi ne("The value is: " + i.ToString());
Console.Read();

Nitin Sharma
(Guru .Net)

*** Sent via Developersdexht tp://www.developersd ex.com***
There is no implicit conversion from int to string. I just checked
the C# specification to make sure. DeveloperX already explained why
the later is faster several posts up. Also, as written, the
performance of those two lines is nearly identical.

Mar 14 '07 #35

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
17450
by: Spammay Blockay | last post by:
I've been tasked with doing technical interviews at my company, and I have generally ask a range of OO, Java, and "good programming technique" concepts. However, one of my favorite exercises I give interviewees seems to trip them up all the time, and I wonder if I'm being too much of a hardass... it seems easy enough to ME, but these guys, when I get them up to the whiteboard, seem to get really confused. The exercise is this:
10
1889
by: Gopal Krish | last post by:
I was asked this question in an interview. How can you display the contents of an ASP page (from another web server) in a aspx page, ie, first half of the screen will display contents from asp and the other half will be from the current aspx page. Using frames is not an option. Any thoughts? (Is this even possible?)
0
6171
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip 2000 Interview questions of .NET , JAVA and SQL Server Interview questions (worth downloading it)
2
6971
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
0
4605
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
18
2869
by: Nobody | last post by:
I've been looking for a job for a while now, and have run into this interview question twice now... and have stupidly kind of blown it twice... (although I've gotten better)... time to finally figure this thing out... basically the interview question is: given an unsorted listed such as: 3,1,3,7,1,2,4,4,3 find the FIRST UNIQUE number, in this case 7... and of course the list can be millions long...
2
7230
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
0
2671
by: freesoftwarepdfs | last post by:
Ultimate list of Interview question website.....Do not miss it http://www.questpond.com http://msdotnetsupport.blogspot.com/2007/01/net-interview-questions-by-dutt-part-2.html http://msdotnetsupport.blogspot.com/2006/08/net-windows-forms-interview-questions.html http://msdotnetsupport.blogspot.com/2006/08/net-remoting-interview-questions.html http://msdotnetsupport.blogspot.com/2006/08/c-interview-questions.html...
0
2236
by: Free PDF | last post by:
..NET , SQL Server interview questions websites.... http://www.questpond.com http://www.geocities.com/dotnetinterviews/ http://msdotnetsupport.blogspot.com/2007/01/net-interview-questions-by-dutt-part-2.html http://msdotnetsupport.blogspot.com/2006/08/net-windows-forms-interview-questions.html http://msdotnetsupport.blogspot.com/2006/08/net-remoting-interview-questions.html...
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10395
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10408
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10137
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9211
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4346
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3874
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3026
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.