- 
                    
- 
                    
- 
                    Abstract usage in C#Can any one give real time example for abstract class and virtual function plz in c#(.NET) 
- 
                    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. 
- 
                    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... 
- 
                    How do I declare inout arguments in C#?The equivalent of inout in C# is ref. , as shown in the following example: public void MyMethod (ref String str1, out String str2) {...}When calling the method, it would be called like this: String s1;String s2;s1 = "Hello";MyMethod(ref s1, out s2);Console.WriteLine(s1);Console.WriteLine(s2);Notice that you need to specify ref when declaring the function and calling it. 
- 
                    Why do I get a "CS5001: does not have an entry point defined" error when compiling?The most common problem is that you used a lowercase 'm' when defining the Main method. The correct way to implement the entry point is as follows: class test {static void Main(string[] args) {}} 
- 
                    How do I create a multilanguage, multifile assembly?Unfortunately, this is currently not supported in the IDE. To do this from the command line, you must compile your projects into netmodules (/target:module on the C# compiler), and then use the command line tool al.exe (alink) to link these netmodules together. 
- 
                    How do I simulate optional parameters to COM calls?You must use the Missing class and pass Missing.Value (in System.Reflection) for any values that have optional parameters. 
- 
                    Is there an equivalent of exit() for quitting a C# .NET application?Yes, you can use System.Environment.Exit(int exitCode) to exit the application or Application.Exit() if it's a Windows Forms app. 
- 
                    How do you specify a custom attribute for the entire assembly (rather than for a class)?Global attributes must appear after any top-level using clauses and before the first type or namespace declarations. An example of this is as follows: using System;[assembly : MyAttributeClass]class X {}Note that in an IDE-created project, by convention, these attributes are placed in AssemblyInfo.cs. 
- 
                    How do I register my code for use by classic COM clients?Use the regasm.exe utility to generate a type library (if needed) and the necessary entries in the Windows Registry to make a class available to classic COM clients. Once a class is registered in the Windows Registry with regasm.exe, a COM client can use the class as though it were a COM class. 
- 
                    Can I define a type that is an alias of another type (like typedef in C++)?Not exactly. You can create an alias within a single file with the "using" directive: using System;using Integer = System.Int32; // aliasBut you can't create a true alias, one that extends beyond the file in which it is declared. Refer to the C# spec for more info on the 'using' statement's scope. 
- 
                    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. 
- 
                    
- 
                    Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace?There is no way to restrict to a namespace. Namespaces are never units of protection. But if you're using assemblies, you can use the 'internal' access modifier to restrict access to only within the assembly. 
- 
                    If I return out of a try/finally in C#, does the code in the finally-clause run?Yes. The code in the finally always runs. If you return out of the try block, or even if you do a "goto" out of the try, the finally block always runs, as shown in the following example: using System;class main {public static void Main() {try {Console.WriteLine("In Try block");return;}finally {Console.WriteLine("In Finally block");}}}Both "In Try block" and "In Finally block" will be displayed. Whether... 
- 
                    Does C# support try-catch-finally blocks?Yes. Try-catch-finally blocks are supported by the C# compiler. Here's an example of a try-catch-finally block: using System;public class TryTest{static void Main(){try{Console.WriteLine("In Try block");throw new ArgumentException();}catch(ArgumentException n1){Console.WriteLine("Catch Block");}finally{Console.WriteLine("Finally Block");}}}Output: In Try BlockCatch BlockFinally Block 
- 
                    Is it possible to have a static indexer in C#?No. Static indexers are not allowed in C#. 
- 
                    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("HARDWARE\DESCRIPTION\System\CentralProcessor\0");value... 
C# Interview Questions

 
  
  
  
		
Ans