C Sharp Interview Questions & Answers part 3
Q: – Explain how to configure Trace switches in the application’s .config file ?
switches are configured using the .config file
<add name="MyTraceSwitch" value="1" />
<add name="TraceSwitch2" value="1" />
both are on.
Q: – Explain how exceptions are handled by the common language runtime in .NET ?
The CLR uses a technique generally referred to as a two-pass exception review process. What this means is that the CLR will process an exception in two passes. In the first pass, the CLR will determine if there is a handler for the exception. This is done by reviewing the entries in the SEH table; specifically it looks at the Try Offset and Try Length flags to see if the exception occurred within a guarded block, and if so, whether the Flags entry dictates that a handler exists for this type of occurrence. Let's assume that the CLR did find a handler during the first pass. At that point the CLR begins a second pass of the SEH table during which it will work through the execution phase of the exception management process. So we can divide the two passes into a discovery pass, in which we determine whether there is a handler in this method context to handle the exception; and an execution pass, in which we actually execute the handler and any special rules.
When code throws an exception, the CLR looks up the call stack looking for a catch filter to handle the exception. When it finds the relevant catch block, before executing the code, it will execute all code in all finally blocks – starting from the try block that threw the exception and stopping with the catch filter that matches the exception. when the CLR encounters an exception for a method it will use the descriptors in the SEH table to determine how to handle the exception, which code block is affected, and what handler should be invoked.
Q: – Describe the different types of user-authored controls in NET ?
User authored controls are which not part of the .net framework library. It includes both custom controls and user controls.
Custom Controls: They look similar to ASP.NET controls. They can be created in one of the 3 ways:-
- Deriving a custom control from existing custom control.
- Making a composite custom control by combining 2 or more existing controls
- By creating a new control from scratch by deriving the control from its base class.
- User Controls: enables a part of ASP.NET page to be reused. The reusable part is in form of a control with the extension .ascx. They look like to be a group of ASP.NET controls which can be used over and over again.
Q: – Explain with code sample how to create a custom control ?
Steps to create a custom control:
- Create a new project.
- Add a custom control to the project.
- Change the name of the class you need to inherit the control from the base class. E.g. inherit the class from System.Windows.Forms.Button if the control s to be inherited from a button class.
- Implement the control with custom properties and featured needed by the control.
- Override the OnPaint method if the control’s appearance needs to be changed.
- Save the build the control
- Reference you control into another or the same project and use the control.
Submitted By:-Goyal Ankur Email-ID: – email@example.com