Does C# support C type macros? No. C# does not have macros. Keep in mind that what some of the predefined C macros (for example, __LINE__ and __FILE__) give you can also be found in .NET classes like System.Diagnostics (for example, StackTrace and StackFrame), but they'll only work on debug builds. Can you store multiple data types in System.Array? No. Is it possible to inline assembly or IL in C# code? No. Can you declare the override method static while the original method is non-static? No, you cannot, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override Does C# support multiple inheritance? No, use interfaces instead. Can multiple catch blocks be executed? No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block. Can you override private virtual methods? No, moreover, you cannot access private methods in inherited cla...
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 me...
How do I convert a string to an int in C#? Here's an example: using System; class StringToInt { public static void Main() { String s = "105"; int x = Convert.ToInt32(s); Console.WriteLine(x); } } How do you directly call a native function exported from a DLL? Here's a quick example of the DllImport attribute in action: using System.Runtime.InteropServices; class C { [DllImport("user32.dll")] public static extern int MessageBoxA(int h, string m, string c, int type); public static int Main() { return MessageBoxA(0, "Hello World!", "Caption", 0); } } This example shows the minimum requirements for declaring a C# method that is implemented in a native DLL. The method C.MessageBoxA() is declared with the static and external modifiers, and has the DllImport attribute, which tells the compiler that the implementation comes from the user32.dll, using the default name of MessageBoxA. For more information, look at the Platform Invoke tutorial ...