Adv C#
Programming


C# Interview Questions and Answers Part 12
111. 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.
112. What does Dispose method do with the connection object?
-
Deletes it from the memory.
113. What is an object pool in .NET?
-
An object pool is a container having objects ready to be used. It tracks the object that is currently in use, total number of objects in the pool. This reduces the overhead of creating and re-creating objects.
114.When you inherit a protected class-level variable, who is it available to?
-
Classes in the same namespace.
115. 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.
117. 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!
118. 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.
119. How can you sort the elements of the array in descending order?
-
By calling Sort() and then Reverse() methods.
120. How do you debug an ASP.NET Web application?
-
Attach the aspnet_wp.exe process to the DbgClr debugger.