C# interview questions and answers
- What debugging tools come with the .NET SDK? CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.
- What does the This window show in the debugger? It points to the object that’s pointed to by this reference. Object’s instance data is shown.
- What does assert() do? In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
- 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.
- Why are there five tracing levels in System.Diagnostics.TraceSwitcher? The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.
- Where is the output of TextWriterTraceListener redirected? To the Console or a text file depending on the parameter passed to the constructor.
- How do you debug an ASP.NET Web application? Attach the aspnet_wp.exe process to the DbgClr debugger.
- What are three test cases you should go through in unit testing? Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).
- Can you change the value of a variable while debugging a C# application? Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.
- Explain the three services model (three-tier application). Presentation (UI), business (logic and underlying code) and data (from storage or other sources).
What is partial classess in .net?
When there is a need to keep the business logic separate from the User Interface or when there is some class which is big enough to have multiple number of developers implement the methods in it, the class can be separated and written in different files as partial class.
The keyword partial must appear in each class.
//syntax for C#
Public partial class MyPartialClassOne
{
//code
}
// this code could be in one file
Public partial class MyPartialClassOne
{
//code
}
// this code could be in another file
C# Interview Questions & Answers, Part 2
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.
13. What class is underneath the SortedList class?
A sorted HashTable.
14. Will the finally block get executed if an exception has not occurred?
Yes.
15. What’s the C# syntax to catch 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 {}.
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).
Interview questions for asp.net Web application developers
- Name a few differences between .NET application and a Java application?
- Specify the best ways to store variables so that we can access them in various pages of ASP.NET application?
- What are the XML files that are important in developing an ASP.NET application?
- What is XSLT and what is its use?
- How do you separate business logic while creating an ASP.NET application?
- If there is a calendar control to be included in each page of your application, and we do not intend to use the Microsoft-provided calendar control, how do you develop it? Do you copy and paste the code into each and very page of your application?
- How do you debug an ASP.NET application?
- How do you deploy an ASP.NET application?
- What is the maximum length of a varchar field in SQL Server?
- How do you define an integer in SQL Server?
Introduction to ASP.NET with C#
Asp, which is now more commonly known as Classic Asp was used extensively in 1990's. The idea of creating dynamic pages and linking them with database was the main purpose of classic Asp. Asp used html controls for user interaction. Apart from the good features available in Asp programming, it also lacks in some of the major areas. These areas include clean coding as asp pages were incline pages and all the business logic as well as the interface was coded in a single page. This produces many problem when the code had to be updated or modified. Asp pages also lacked performance and scalability which were fixed in Asp.net. Lets see what Asp.net technology has to offer a developer to build dynamic pages much faster.
Language Options:
Asp.net provides lets you choose the scripting language between javascript and VbScript. This is beneficial for the java programmers as well as the VB programmers since they already have the basic background of the language.
Caching features:
Asp.net also introduces caching features which increases the performance of the application. Caching allows the developer to save the recently used data in a cache variable so that if does not have to spend any time looking for it in the future when anyone requests it.
Use of Controls:
Asp.net provides the developer with several controls to perform basic as well as advanced operations. Controls provided in Asp.net falls under HTML Controls, HTML Server Controls and Web Server Controls.
HTML Controls:
Html controls are the basic controls that are executed on the client machine. These controls include textbox, label , image etc. A simple example of html control can be given by the following code which renders an image.
As you see HTML controls are very easy to use but they don't provide much features. Microsoft decided to introduce HTML Server controls which extends the functionality of simple HTML Controls.
HTML Server Controls:
HTML Server Controls looks exactly like the HTML Controls with one difference that they are executed on the server rather than the client. A simple example of HTML Server controls is given below:
just add a runat server attribute with the image tag.
As you can see that the image tag or control looks exactly like the one that we have previously discussed. But it has an additional attribute which is runat. The runat attribute denotes that this is a HTML Server Control and will be executed on the Server rather than the client.
Note: src attribute in the image tag denotes the path of the image it can be "C:MyDirectorymyImage.jpg"
Asp.net Web Applications:
Asp.net is based on the .NET framework for building web applications. Since Asp.net is a part of the Microsoft. NET Framework it has the ability to take advantage of rich class libraries provided by Microsoft. The question is that why should one use Asp.net and not use classic asp or any other web programming technology. Here are some of the features of Asp.net that makes it the best web application technology.
Web Server Controls
Web Server Controls are the most advanced controls in Asp.net. Each control comes with tons of features that allows the developer to complete the task in less time.Web Server Controls are executed on the Server. Web Server Controls include datagrid control, datalist control, calendar control and many many more.
Special Note:
When dealing with different types of controls one must always remember that when to use which control. If the control will only act as a static entity than you should always use HTML Controls. If the control will be dynamic you should useWeb Server Controls.