C Sharp Interview Questions & Answers part 2

0
481

Q: – 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.

Q: – 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.

Q: – 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:

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

Q: – 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);

Q: – 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);
}
}

Q: – 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);
GetAge();
}

public static void OnMyEvent(MyEventArgse)
{
if(MyEvent!=null)
MyEvent(new object(),e);
}

public static void GetAge()
{
MyEventArgse1 = new MyEventArgs(25);
OnMyEvent(e1);
}
}

Q: – 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 break point.

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

Q: – 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”.

Q: – 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",
"module1");

Submitted By:-Goyal Ankur            Email-ID: – goyal.ankur30@yahoo.in

SHARE

LEAVE A REPLY