C# Interview Questions And Answers Part - 9
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);
}
}
How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.
How do you debug an ASP.NET Web application?
Attach the aspnet_wp.exe process to the DbgClr debugger.
How do you mark a method obsolete?
Assuming you've done a "using System;": [Obsolete]
public int Foo() {...}
or [Obsolete("This is a message describing why this method is obsolete")]
public int Foo() {...}
Note: The O in Obsolete is capitalized.
How is the DLL Hell problem solved in .NET?
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly
What are the ways to deploy an assembly?
An MSI installer, a CAB archive, and XCOPY command.
Why does DllImport not work for me?
All methods marked with the DllImport attribute must be marked as public static extern.
What is a delegate?
A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.
What is the difference between an interface and abstract class?
In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.
What is an abstract class?
A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it is a blueprint for a class without any implementation.
_break
Does C# support multiple-inheritance?
No.
Who is a protected class-level variable available to?
It is available to any sub-class (a class inheriting this class).
Can you store multiple data types in System.Array?
No.
What’s the top .NET class that everything is derived from?
System.Object.
What does the term immutable mean?
The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.
What’s the difference between System.String and System.Text.StringBuilder classes?
System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
The first one performs a deep copy of the array, the second one is shallow. A shallow copy of an Array copies only the elements of the Array, whether they are reference types or value types, but it does not copy the objects that the references refer to. The references in the new Array point to the same objects that the references in the original Array point to. In contrast, a deep copy of an Array copies the elements and everything directly or indirectly referenced by the elements.
Page numbers : 1 2 3 4 5 6 7 8 9 10 11 12 13