What is c#(c sharp programming language)?

C# (pronounced see sharp) is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines. It was developed by Microsoft within its .NET initiative. C# is one of the programming languages designed for the Common Language Infrastructure.

Explain the elements of the .NET Framework.

(Common Language Runtime): It is a common managed environment where all the .net programs run. Supports multiple languages and has the garbage collector.

.Net Framework Class Libraries: For each source code compiler (VB.NET, C#.NET, etc.), there is a minimum set of coding standards that must be met. The minimum set of coding standards that must be met to compile .NET code into MSIL code is known as CLS – Common Language Specification. The role of the Common Language Specification is to ensure that all generated code (MSIL) that meets the minimum set of coding standards can operate successfully within the .NET framework. THE CTS (Common Type System) handles conversion of programming-language data types into .NET compatible (MSIL) data types. The implicit benefit of the CTS is the reduction of development time when attempting to coordinate data types between two sets of different programming-language code.

Data and XML: Support for disconnected programming model and XML.
XML webservices: creating webservices for distributed architecture.
Webforms: Provides support and functionality for Web based UI.
Windows forms: Provides support and functionality for Windows based UI.

What is assembly manifest? What is the information it provides?

Assembly Manifest is a file that contains data that describes how the elements present inside an assembly are connected to each other. The assembly manifest contains assembly metadata to define the scope of the assembly and resolve references to resources and classes.

Information provided by Assembly Manifest:

  • Assembly Name
  • Version Number
  • Culture
  • Strong name
  • List of files inside the assembly
  • Reference information

Explain how a .NET application is compiled and executed?

Any code written in any .NET complaint languages when compiled, converts into MSIL (Microsoft Intermediate Language) code in form of an assembly through CLS, CTS. IL is the language that CLR can understand. On execution, this IL is converted into binary code by CLR’s just in time compiler (JIT) and these assemblies or DLL are loaded into the memory.

Describe the .NET base class library?

.NET’s Base class library exists in order to encapsulate huge number of common functions and makes them easily accessible to the developer. .NET base class library provides the functionality like ADO.NET, XML, Threading, IO, Security, Diagnostics, Resources, Globalization, collections etc. It serves as the main point of interaction between developer and runtime.

Explain the difference between value types and reference types in C#?

Value Type:

  • Stores the data.
  • The value of value types is stored on the managed stack.
  • One variable can have just one value.
  • They are lighter objects.

Reference Type:

  • Stores the reference to the data.
  • A reference type is allocated on the heap.
  • several variables can reference the same data
  • They are heavier objects.

Explain the importance of Imports and Using Statements.

Import statement: creates a property on the global object with the name supplied as namespace and initializes it to contain the object that corresponds to the namespace being imported. Any properties created using the import statement cannot be assigned to, deleted, or enumerated. All import statements are executed when a script starts.

Using statements: mainly defines the namespaces whose objects will be used in the form. This clearly solves 2 purposes: Defines all the namespaces that will be used in a form. Secondly, reduces the hassle for the programmer to type the name of namespace again and again while using classes/objects that belong to the namespace.

Explain the difference between a class and a structure


  • It is reference type.
  • Null value can be assigned to a variable in a class
  • It can have destructor.
  • All variables in classes are by default private.
  • Good to be used from architecture view as it provides high flexibility.


  • It is value type.
  • Null value assignment is not feasible here.
  • Cannot have destructor.
  • All variables in structures are public.
  • Good to be used for simple data structures.

Explain how garbage collection manages the reclaimation of unused memory.

The garbage collector assumes that all objects in the managed heap are garbage. It starts walking the roots and builds a graph of all objects reachable from the roots recursively. It stops when it attempts to add an object to the graph that it previously added. The graph contains the set of all objects that are reachable from the application’s roots. Any object/s that is not in the graph is not accessible by the application and is considered garbage. Collection only occurs when the heap is full. In such a case, each and every garbage object calls the Finalize method and reclaims the unused memory.

Explain how garbage collection deals with circular references?

The .Net runtime knows about all the references between the objects. It can identify all the circular references that are reachable from the root and hence finalize them to free them all at once if and when needed.

Explain the process of creating a menu using the MainMenu component?

MainMenu component is a component that allows the display of Menus at runtime on a form.

Process of creating Menu using MainMenu Component:

  • Add MainMenu component on Windows Form.
  • Menu designer allows deciding the structure of the main menu by selecting the Type Here area and adding the Menu Items to be displayed on the menu.
  • Add functionality to Menu Items as required.

Explain the process of creating a context menu using the ContextMenu component?

ContextMenu component provides the users with the ability to access some very frequently used commands. Context menu works by right click of mouse. They mainly provide access to commands particular to the control that has been clicked upon.

Process for creating context menus:

  • Open the windows form application.
  • Select ContextMenu component from toolbox.
  • A menu is added. Click on Type here and type in new Menu Items to be placed on the Menu.
  • Provide the functionality.
  • Associate the context menu with the form or the control it is supposed to be related to.

What is a delegate? Explain how to create it?

A delegate declares a ref type that references a named of anonymous method. Delegates are secure and type-safe. Consider them as type safe function pointers.

public delegate void Del<T>(T item);
Del<int> d1 = new Del<int>(Notify);

Explain how to declare and raise events from your application?

Declare Events: “Event” keyword is used to declare an event.

public delegate void MyCustomHandler(object o, MyEventArgse);
public class MyEventArgs: EventArgs
    public readonly int Age;
    public MyEventArgs(int age)
        Age = age;

public class MyCustomListener
    public void Show(object o, MyEventArgs e)
        Console.WriteLine("Age is {0}", e.Age);

Describe how to implement event handlers and associate them with events?

public class MyClass
        public static event MyCustomHandler MyEvent;
    public static void Main()
        MyCustomListener mcll = new MyCustomListener();
        MyEvent += new MyCustomHandler(mcl1.Show);
    public static void OnMyEvent(MyEventArgse)
        MyEvent(new object(),e);
    public static void GetAge()
        MyEventArgse1 = new MyEventArgs(25);

What is Break Mode? How to set breakpoints?

Break mode is the state of an application when the execution gets paused and allows the developer to edit the value in the current state. To attain a break mode we can do any of the following steps:

1. Selecting Break from the Run menu (Ctrl+Break) or pressing the pause button.
2. Reaching to breakpoint.

Setting up the break points:
1. Go to the line where you need to mark the breakpoint.
2. Click with mouse on left corner margin of that line.
3. Another way is to press F9

Describe how to step through code in .NET?

1. Steps to step through the code in .NET:
2. Start the program in debug mode.

  • When the first breakpoint is reached then step through can be done in one of the two ways:
  • Press F10 to move to next line.

3. Select debug menu and click on step over. This would step over the breakpoint to next level.
4. Other options are: “Step Into” and “Step Out”.

What are Trace switches? Describe how to create and use Trace switches?

Trace switches allow us to filter, enable/disable the outputs through Trace. We can configure them through the config file. 3 types of trace switches:

  • BooleanSwitch: Enable/Disable trace statements.
  • TraceSwitch and SourceSwitch: used for trapping particular Trace levels.
BooleanSwitch dataSwitch =
new BooleanSwitch("Comment", "module1");
TraceSwitch generalSwitch =
new TraceSwitch("comment",

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.

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.

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.

1. 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.

2. 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.

Explain with code sample how to create a custom control?

Steps to create a custom control:

1. Create a new project.
2. Add a custom control to the project.
3. 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.
4. Implement the control with custom properties and featured needed by the control.
5. Override the OnPaint method if the control’s appearance needs to be changed.
6. Save the build the control
7. Reference you control into another or the same project and use the control.