Some Interview questions

W

weird0

Why did u use stringbuilder instead of string for appending?

I told him it is more efficient. He did not seem very convinced. So
what should have been the exact answer.

How many objects will be formed in the operation a=b+c; ? (a,b and c
are objects)

What is the difference between a pointer and reference ?

a ptr can be null but a ref cannot be null... please elaborate .. i
cant understand thru some code examples to clear my concept...


Unemployed
 
J

Jon Skeet [C# MVP]

Why did u use stringbuilder instead of string for appending?

I told him it is more efficient. He did not seem very convinced. So
what should have been the exact answer.

Could you say what your code actually was? Sometimes StringBuilder is
more efficient - sometimes it isn't.

See http://pobox.com/~skeet/csharp/stringbuilder.html for more
information.
How many objects will be formed in the operation a=b+c; ? (a,b and c
are objects)

It will depend on what the objects actually are.
What is the difference between a pointer and reference ?

a ptr can be null but a ref cannot be null... please elaborate .. i
cant understand thru some code examples to clear my concept...

A reference certainly can be null - in C#, at least. In C#, pointers
are only used in unsafe code.

Jon
 
W

weird0

Suppose if the objects a,b and c are (three cases):-
1.int
2.float
3.belong to user-defined class like Date
 
J

Jon Skeet [C# MVP]

Suppose if the objects a,b and c are (three cases):-
1.int
2.float
3.belong to user-defined class like Date

If they're all ints, no objects will be created.
If they're all floats, no objects will be created.
Not sure what you mean by Date - if you mean DateTime, it's a struct
and you'd get a compile-time error because you can't add two DateTimes
together.

Jon
 
P

PS

weird0 said:
Why did u use stringbuilder instead of string for appending?

I told him it is more efficient. He did not seem very convinced. So
what should have been the exact answer.

If that is YOUR reason to use a StringBuilder then it is the correct answer
in some respects. I use a StringBuilder if it makes the code cleaner and
easier to understand what is happening. Performance (if improved) is an
added benefit but it is not my primary reason to use it.
How many objects will be formed in the operation a=b+c; ? (a,b and c
are objects)

What is the difference between a pointer and reference ?

a ptr can be null but a ref cannot be null... please elaborate .. i
cant understand thru some code examples to clear my concept...

These last 2 questions seem pointless to me. I really don't know what they
are trying to ascertain from asking questions like this. At least the first
one finds out something of your rationale about your coding style.

The first question I like to ask is "Have you read Design Patterns?"

PS
 
S

Samuel R. Neff

We always ask about design patterns too but it's amazing how many
people can explain exactly what they are and give textbook responses
of their impelmentation, but then 2 seconds later choose not to use
them in an example where they obviously apply.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
 
H

Helge Jensen

Samuel R. Neff skrev:
We always ask about design patterns too but it's amazing how many
people can explain exactly what they are and give textbook responses
of their impelmentation, but then 2 seconds later choose not to use
them in an example where they obviously apply.

Or use them where they are obviously overengineered solutions to
problems that aren't there :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top