Friday 18 September 2015

Tricky C#.Net Interview Questions and Answers for freshers and experienced pdf

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

122. What does Dispose method do with the connection object? 
Deletes it from the memory.

123. How do you generate documentation from the C# file commented properly with a command-line compiler?
Compile it with a /doc switch.

124. When you inherit a protected class-level variable, who is it available to? 
Classes in the same namespace.

125. How can I get the ASCII code for a character in C#? 
Casting the char to an int will give you the ASCII value: char c = 'f'; System.Console.WriteLine((int)c); or for a character in a string: System.Console.WriteLine((int)s[3]); The base class libraries also offer ways to do this with the Convert class or Encoding classes if you need a particular encoding.

126. Is there an equivalent to the instanceof operator in Visual J++? 
C# has the is operator:
expr is type
How do I create a Delegate/MulticastDelegate?
C# requires only a single parameter for delegates: the method address. Unlike other languages, where the programmer must specify an object reference and the method to invoke, C# can infer both pieces of information by just specifying the method's name. For example, let's use System.Threading.ThreadStart: Foo MyFoo = new Foo(); ThreadStart del = new ThreadStart(MyFoo.Baz); This means that delegates can invoke static class methods and instance methods with the exact same syntax!

127. How do destructors and garbage collection work in C#? 
C# has finalizers (similar to destructors except that the runtime doesn't guarantee they'll be called), and they are specified as follows:
class C
{
~C()
{
// your code
}
public static void Main() {}
}
Currently, they override object.Finalize(), which is called during the GC process.

128. My switch statement works differently! Why? 
C# does not support an explicit fall through for case blocks.
The following code is not legal and will not compile in C#: switch(x)
{
case 0:
// do something
case 1:
// do something in common with 0
default:
// do something in common with
//0, 1 and everything else
break;
}
To achieve the same effect in C#, the code must be modified
as shown below (notice how the control flows are explicit): class Test
{
public static void Main()
{
int x = 3;
switch(x)
{
case 0:
// do something
goto case 1;
case 1:
// do something in common with 0
goto default;
default:
// do something in common with 0, 1, and anything else
break;
}
}
}

129. How can I access the registry from C# code? 
By using the Registry and RegistryKey classes in Microsoft.Win32, you can easily access the registry. The following is a sample that reads a key and displays its value:
using System;using Microsoft.Win32;
class regTest
{
public static void Main(String[] args)
{
RegistryKey regKey;
Object value;
regKey = Registry.LocalMachine;
regKey =
regKey.OpenSubKey("HARDWAREDESCRIPTIONSystemCentralProcessor ");
value = regKey.GetValue("VendorIdentifier");
Console.WriteLine("The central processor of this machine is: {0}.", value);
}
}

130. How can you sort the elements of the array in descending order? 
By calling Sort() and then Reverse() methods.


More Questions & Answers:-

No comments:

Post a Comment