C# Basic Que
C# Basic Que
This is a list of questions I have gathered from other sources and created myself over a
period of time from my experience, many of which I felt where incomplete or simply
wrong. I have finally taken the time to go through each question and correct them to the
best of my ability. However, please feel free to post feedback to challenge, improve, or
suggest new questions. I want to thank those of you that have contributed quality
questions and corrections thus far.
There are some question in this list that I do not consider to be good questions for an
interview. However, they do exist on other lists available on the Internet so I felt
compelled to keep them easy access.
General Questions
11. How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.
12. What’s the .NET collection class that allows an element to be accessed using
a unique key?
HashTable.
14. Will the finally block get executed if an exception has not occurred?
Yes.
16. Can multiple catch blocks be executed for a single try statement?
No. Once the proper catch block processed, control is transferred to the finally
block (if there are any).
17. Explain the three services model commonly know as a three-tier application.
Presentation (UI), Business (logic and underlying code) and Data (from storage or
other sources).
Class Questions
2. Can you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited.
3. Can you allow a class to be inherited, but prevent the method from being
over-ridden?
Yes. Just leave the class public and make the method sealed.
7. Why can’t you specify the accessibility modifier for methods inside the
interface?
They all must be public, and are therefore public by default.
9. What happens if you inherit multiple interfaces and they have conflicting
method names?
It’s up to you to implement the method inside your own class, so implementation
is left entirely up to you. This might cause a problem on a higher-level scale if
similarly named methods from different interfaces expect different data, but as far
as compiler cares you’re okay.
To Do: Investigate
1. What’s the implicit name of the parameter that gets passed into the set
method/property of a class?
Value. The data type of the value parameter is defined by whatever data type the
property is declared as.
4. Can you declare an override method to be static if the original method is not
static?
No. The signature of the virtual method must remain the same. (Note: Only the
keyword virtual is changed to keyword override)
1. What’s a delegate?
A delegate object encapsulates a reference to a method.
1. Is XML case-sensitive?
Yes.
3. What’s the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace
class for both debug and release builds.
7. What are three test cases you should go through in unit testing?
1. Positive test cases (correct data, correct output).
2. Negative test cases (broken or missing data, proper handling).
3. Exception test cases (exceptions are thrown and caught properly).
7. What does the Initial Catalog parameter define in the connection string?
The database name to connect to.
Assembly Questions