Friday, April 10, 2009

C# interview questions Set 1



Note: Please naviagate to the other set of questions by clicking the links in the "Other Questions" section on the right hand side

1. Does C# support multiple-inheritance?

No, use interfaces instead.

2. When you inherit a protected class-level variable, who is it available to?

Classes in the same namespace.

3. Are private class-level variables inherited?

Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.

4. Describe the accessibility modifier “protected internal”.

It is available to derived classes and classes within the same Assembly (and
naturally from the base class it’s declared in).

5. C# provides a default class constructor for me. I decide to write a constructor that takes a string as a parameter, but want to keep the constructor that has no parameter. How many constructors should I write?

Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

6.What’s the top .NET class that everything is derived from?

System.Object.

7. How to implement encapsulation in C#.

Through Properties.

8. What’s the difference between System.String and System.StringBuilder classes?

System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

9.What’s the advantage of using System.Text.StringBuilder over System.String?

StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time it’s being operated on, a new instance is created.

10. Can you store multiple data types in System.Array?

No.

12. How can you sort the elements of the array in descending order?

By calling Sort() and then Reverse() methods.

13. What’s the .NET class that allows the retrieval of a data element using a unique key?

HashTable.

14. What class is underneath the SortedList class?

A sorted HashTable.

15. Will the finally block get executed if an exception has not occurred?

Yes.

16. What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?

A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

17. Can multiple catch blocks be executed?

No. Once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.

18. 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).

19. What is the role of the DataReader class in ADO.NET connections?


It returns a read-only dataset from the data source when the command is executed.

Other ASP.Net related interview questions are available at
Set 1 of ASP.Net Interview questions or Asp.Net FAQs
Set 2 of ASP.Net Interview questions or Asp.Net FAQs
Set 3 of ASP.Net Interview questions or ASP.Net FAQs
New features of C# 4.0 is available at C# 4.0 FAQs or C# 4.0
Basic .Net questions are available at .Net Frame works FAQ or .Net interview question
Web Service interview question are available at Web Service Interview questions

No comments: