InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 51. |
How Do I Declare Inout Arguments In C#? |
|
Answer» The equivalent of INOUT in C# is ref. , as shown in the following example: The equivalent of inout in C# is ref. , as shown in the following example: |
|
| 52. |
How Can I Create A Process That Is Running A Supplied Native Executable (e.g., Cmd.exe)? |
|
Answer» <P>The following code should run the executable and wait for it to exit before continuing: The following code should run the executable and wait for it to exit before continuing: |
|
| 53. |
What Optimizations Does The C# Compiler Perform When You Use The /optimize+ Compiler Option? |
|
Answer» The following is a response from a developer on the C# compiler team: The following is a response from a developer on the C# compiler team: |
|
| 54. |
Why Do I Get A "cs5001: Does Not Have An Entry Point Defined" Error When Compiling? |
|
Answer» 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: 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: |
|
| 55. |
What Is The Syntax For Calling An Overloaded Constructor Within A Constructor (this() And Constructorname() Does Not Compile)? |
|
Answer» The syntax for calling ANOTHER CONSTRUCTOR is as follows: The syntax for calling another constructor is as follows: |
|
| 56. |
Why Do I Get A Syntax Error When Trying To Declare A Variable Called Checked? |
|
Answer» The WORD CHECKED is a KEYWORD in C#. The word checked is a keyword in C#. |
|
| 57. |
Is It Possible To Restrict The Scope Of A Field/method Of A Class To The Classes In The Same Namespace? |
|
Answer» 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. 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. |
|
| 58. |
Why Cannot You Specify The Accessibility Modifier For Methods Inside The Interface? |
|
Answer» They all must be public. Therefore, to prevent you from GETTING the false IMPRESSION that you have any freedom of choice, you are not allowed to SPECIFY any ACCESSIBILITY, it is public by default. They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it is public by default. |
|
| 59. |
How Do I Create A Multilanguage, Single-file Assembly? |
|
Answer» This is CURRENTLY not SUPPORTED by VISUAL STUDIO .NET. This is currently not supported by Visual Studio .NET. |
|
| 60. |
What Is The Equivalent To Regsvr32 And Regsvr32 /u A File In .net Development? |
|
Answer» TRY using RegAsm.exe. The general syntax would be: RegAsm. A good DESCRIPTION of RegAsm and its ASSOCIATED switches is located in the .NET SDK docs. Just search on "Assembly Registration Tool".Explain ACID rule of thumb for transactions. Transaction must be Atomic (it is one unit of work and does not DEPENDENT on previous and following transactions), Consistent (data is either committed or roll back, no in-between case where something has been updated and something hasnot), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after). Try using RegAsm.exe. The general syntax would be: RegAsm. A good description of RegAsm and its associated switches is located in the .NET SDK docs. Just search on "Assembly Registration Tool".Explain ACID rule of thumb for transactions. Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no in-between case where something has been updated and something hasnot), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after). |
|
| 61. |
How Do I Create A Multi Language, Multi File Assembly? |
|
Answer» 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. 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. |
|
| 62. |
How Do I Do Implement A Trace And Assert? |
|
Answer» Use a conditional attribute on the method, as shown below: In this example, the call to Debug.Trace() is made only if the preprocessor symbol TRACE is DEFINED at the call SITE. You can define preprocessor symbols on the command line by using the /D switch. The restriction on conditional methods is that they must have void return type. Use a conditional attribute on the method, as shown below: In this example, the call to Debug.Trace() is made only if the preprocessor symbol TRACE is defined at the call site. You can define preprocessor symbols on the command line by using the /D switch. The restriction on conditional methods is that they must have void return type. |
|
| 63. |
How Do I Register My Code For Use By Classic Com Clients? |
|
Answer» 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. 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. |
|
| 64. |
Why Would You Use Untrusted Verification? |
|
Answer» WEB SERVICES MIGHT use it, as WELL as non-Windows applications. Web Services might use it, as well as non-Windows applications. |
|
| 65. |
How Is Method Overriding Different From Overloading? |
|
Answer» When overriding, you CHANGE the method behavior for a derived class. OVERLOADING SIMPLY involves having a method with the same name WITHIN the class. When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class. |
|
| 66. |
Does C# Support Properties Of Array Types? |
|
Answer» Yes. Here's a simple example: Yes. Here's a simple example: |
|
| 67. |
Is There A Way To Force Garbage Collection? |
|
Answer» YES. SET all references to null and then call System.GC.Collect(). If you need to have some OBJECTS DESTRUCTED, and System.GC.Collect() doesn't seem to be doing it for you, you can force finalizers to be RUN by setting all the references to the object to null and then calling System.GC.RunFinalizers(). Yes. Set all references to null and then call System.GC.Collect(). If you need to have some objects destructed, and System.GC.Collect() doesn't seem to be doing it for you, you can force finalizers to be run by setting all the references to the object to null and then calling System.GC.RunFinalizers(). |
|
| 68. |
Is There Regular Expression (regex) Support Available To C# Developers? |
|
Answer» Yes. The .NET class LIBRARIES PROVIDE support for REGULAR expressions. Look at the documentation for the SYSTEM. Text.Regular Expressions NAMESPACE. Yes. The .NET class libraries provide support for regular expressions. Look at the documentation for the System. Text.Regular Expressions namespace. |
|
| 69. |
What Is The C# Equivalent Of C++ Catch (....), Which Was A Catch-all Statement For Any Possible Exception? Does C# Support Try-catch-finally Blocks? |
|
Answer» Yes. Try-catch-finally blocks are supported by the C# compiler. Here's an example of a try-catch-finally block: 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: Both "In Try block" and "In Finally block" will be displayed. Whether the return is in the try block or after the try-finally block, performance is not affected either WAY. The compiler treats it as if the return were OUTSIDE the try block anyway. If it's a return without an expression (as it is above), the IL emitted is identical whether the return is inside or outside of the try. If the return has an expression, there's an extra store/load of the value of the expression (since it has to be computed within the try block). Yes. Try-catch-finally blocks are supported by the C# compiler. Here's an example of a try-catch-finally block: 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: Both "In Try block" and "In Finally block" will be displayed. Whether the return is in the try block or after the try-finally block, performance is not affected either way. The compiler treats it as if the return were outside the try block anyway. If it's a return without an expression (as it is above), the IL emitted is identical whether the return is inside or outside of the try. If the return has an expression, there's an extra store/load of the value of the expression (since it has to be computed within the try block). |
|
| 70. |
How Do I Make A Dll In C#? |
|
Answer» You NEED to USE the /TARGET:LIBRARY compiler option. You need to use the /target:library compiler option. |
|
| 71. |
I Was Trying To Use An "out Int" Parameter In One Of My Functions. How Should I Declare The Variable That I Am Passing To It? |
|
Answer» You should DECLARE the variable as an int, but when you pass it in you MUST specify it as 'out', like the FOLLOWING: You should declare the variable as an int, but when you pass it in you must specify it as 'out', like the following: |
|
| 72. |
Is There An Equivalent Of Exit() For Quitting A C# .net Application? |
|
Answer» Yes, you can USE System.Environment.Exit(INT exitCode) to exit the application or Application.Exit() if it's a WINDOWS Forms APP. Yes, you can use System.Environment.Exit(int exitCode) to exit the application or Application.Exit() if it's a Windows Forms app. |
|
| 73. |
So Let's Say I Have An Application That Uses Myapp.dll Assembly, Version 1.0.0.0. There Is A Security Bug In That Assembly, And I Publish The Patch, Issuing It Under Name Myapp.dll 1.1.0.0. How Do I Tell The Client Applications That Are Already Installed To Start Using This New Myapp.dll? |
|
Answer» USE publisher policy. To CONFIGURE a publisher policy, use the publisher policy configuration file, which uses a format similar app .CONFIG file. But unlike the app .config file, a publisher policy file needs to be compiled into an assembly and PLACED in the GAC. Use publisher policy. To configure a publisher policy, use the publisher policy configuration file, which uses a format similar app .config file. But unlike the app .config file, a publisher policy file needs to be compiled into an assembly and placed in the GAC. |
|
| 74. |
Can You Have Two Files With The Same File Name In Gac? |
|
Answer» Yes, remember that GAC is a very special FOLDER, and while normally you WOULD not be able to place two files with the same name into a Windows folder, GAC differentiates by version number as WELL, so it’s possible for MyApp.dll and MyApp.dll to co-exist in GAC if the first one is version 1.0.0.0 and the second one is 1.1.0.0. Yes, remember that GAC is a very special folder, and while normally you would not be able to place two files with the same name into a Windows folder, GAC differentiates by version number as well, so it’s possible for MyApp.dll and MyApp.dll to co-exist in GAC if the first one is version 1.0.0.0 and the second one is 1.1.0.0. |
|
| 75. |
Where's Global Assembly Cache Located On The System? |
|
Answer» USUALLY C:\winnt\assembly or C:\windows\assembly. Usually C:\winnt\assembly or C:\windows\assembly. |
|
| 76. |
How Can You Create A Strong Name For A .net Assembly? |
|
Answer» With the HELP of STRONG NAME TOOL (sn.exe). With the help of Strong Name tool (sn.exe). |
|
| 78. |
How Can You Debug Failed Assembly Binds? |
|
Answer» Use the Assembly BINDING Log VIEWER (fuslogvw.exe) to FIND out the paths SEARCHED. Use the Assembly Binding Log Viewer (fuslogvw.exe) to find out the paths searched. |
|
| 79. |
How Can You Tell The Application To Look For Assemblies At The Locations Other Than Its Own Install? |
|
Answer» USE the directive in the XML .CONFIG file for a given application. Use the directive in the XML .config file for a given application. |
|
| 80. |
What's A Strong Name? |
|
Answer» A strong name includes the name of the ASSEMBLY, version number, CULTURE identity, and a PUBLIC KEY token. A strong name includes the name of the assembly, version number, culture identity, and a public key token. |
|
| 81. |
What's The Difference Between Private And Shared Assembly? |
|
Answer» Private assembly is used inside an APPLICATION only and does not have to be identified by a strong name. Shared assembly can be used by MULTIPLE applications and has to have a strong name. Private assembly is used inside an application only and does not have to be identified by a strong name. Shared assembly can be used by multiple applications and has to have a strong name. |
|
| 82. |
What Do You Know About .net Assemblies? |
|
Answer» Assemblies are the smallest units of versioning and deployment in the .NET application. Assemblies are also the building blocks for PROGRAMS such as WEB services, Windows services, SERVICED COMPONENTS, and .NET remoting applications. Assemblies are the smallest units of versioning and deployment in the .NET application. Assemblies are also the building blocks for programs such as Web services, Windows services, serviced components, and .NET remoting applications. |
|
| 83. |
How Do I Simulate Optional Parameters To Com Calls? |
|
Answer» You MUST USE the Missing CLASS and pass Missing.Value (in System.Reflection) for any values that have OPTIONAL parameters. You must use the Missing class and pass Missing.Value (in System.Reflection) for any values that have optional parameters. |
|
| 84. |
How Do You Directly Call A Native Function Exported From A Dll? |
|
Answer» Here’s a quick example of the DllImport attribute in action: using System.Runtime.InteropServices; 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 Message BoxA. For more information, look at the Platform Invoke tutorial in the documentation. Here’s a quick example of the DllImport attribute in action: using System.Runtime.InteropServices; 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 Message BoxA. For more information, look at the Platform Invoke tutorial in the documentation. |
|
| 85. |
How Do You Implement Thread Synchronization (object.wait, Notify,and Criticalsection) In C#? |
|
Answer» You WANT the LOCK statement, which is the same as Monitor Enter/Exit: You want the lock statement, which is the same as Monitor Enter/Exit: |
|
| 86. |
How Do You Mark A Method Obsolete? |
|
Answer» [OBSOLETE] public int FOO() {...} [Obsolete] public int Foo() {...} |
|
| 87. |
How Do You Specify A Custom Attribute For The Entire Assembly (rather Than For A Class)? |
|
Answer» 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: 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: |
|
| 88. |
How Does One Compare Strings In C#? |
|
Answer» In the past, you had to call .ToString() on the strings when using the == or != operators to compare the strings’ values. That will still work, but the C# compiler now automatically compares the values instead of the references when the == or != operators are used on string types. If you actually do want to compare references, it can be DONE as follows: if ((object) str1 == (object) STR2) { } Here’s an example showing how string compares work: Output: In the past, you had to call .ToString() on the strings when using the == or != operators to compare the strings’ values. That will still work, but the C# compiler now automatically compares the values instead of the references when the == or != operators are used on string types. If you actually do want to compare references, it can be done as follows: if ((object) str1 == (object) str2) { } Here’s an example showing how string compares work: Output: |
|
| 89. |
I Was Trying To Use An Out Int Parameter In One Of My Functions. How Should I Declare The Variable That I Am Passing To It? |
|
Answer» You should declare the VARIABLE as an int, but when you pass it in you MUST specify it as ‘out’, LIKE the following: int i; FOO(out i); where foo is declared as FOLLOWS: You should declare the variable as an int, but when you pass it in you must specify it as ‘out’, like the following: int i; foo(out i); where foo is declared as follows: |
|
| 90. |
If I Return Out Of A Try/finally In C#, Does The Code In The Finally-clause Run? |
|
Answer» 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: Both In Try block and In Finally block will be displayed. Whether the return is in the try block or after the try-finally block, performance is not affected either way. The compiler treats it as if the return were OUTSIDE the try block anyway. If it’s a return without an expression (as it is above), the IL emitted is identical whether the return is inside or outside of the try. If the return has an expression, there’s an extra store/load of the value of the expression (since it has to be computed WITHIN the try block). 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: Both In Try block and In Finally block will be displayed. Whether the return is in the try block or after the try-finally block, performance is not affected either way. The compiler treats it as if the return were outside the try block anyway. If it’s a return without an expression (as it is above), the IL emitted is identical whether the return is inside or outside of the try. If the return has an expression, there’s an extra store/load of the value of the expression (since it has to be computed within the try block). |
|
| 91. |
Is It Possible To Have A Static Indexer In C#? Allowed In C#. |
|
Answer» No. Static indexers are not |
|
| 92. |
Is It Possible To Have Different Access Modifiers On The Get/set Methods Of A Property? |
|
Answer» No. The access modifier on a PROPERTY applies to both its get and set ACCESSORS. What you NEED to do if you want them to be different is MAKE the property read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property. No. The access modifier on a property applies to both its get and set accessors. What you need to do if you want them to be different is make the property read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property. |
|
| 93. |
Is It Possible To Inline Assembly Or Il In C# Code? |
|
Answer» No. No. |
|
| 94. |
What's C# ? |
|
Answer» C# (pronounced C-sharp) is a new object oriented LANGUAGE from Microsoft and is derived from C and C++. It also borrows a LOT of concepts from JAVA too including garbage COLLECTION. C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection. |
|
| 95. |
What Does The Dispose Method Do With The Connection Object? |
|
Answer» DISPOSE PLACES the CONNECTION backing the MANAGED POOL. So that other objects/class can use the connection for further use. Dispose places the connection backing the managed pool. So that other objects/class can use the connection for further use. |
|
| 96. |
Between Windows Authentication And Sql Server Authentication, Which One Is Trusted And Which One Is Untrusted? |
|
Answer» Windows Authentication is trusted because the username and password are checked with the ACTIVE Directory, the SQL Server authentication is UNTRUSTED, since SQL Server is the only VERIFIER participating in the TRANSACTION. Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction. |
|
| 97. |
What Is The Wildcard Character In Sql? |
|
Answer» Let’s say you want to QUERY DATABASE with LIKE for all employees whose NAME STARTS with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’. Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’. |
|
| 98. |
What's The Difference Between The Debug Class And Trace Class? |
|
Answer» DOCUMENTATION LOOKS the same. USE Debug class for debug builds, use Trace class for both debug and release builds. Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds. |
|
| 99. |
What Does Assert() Method Do? |
|
Answer» In debug compilation, assert takes in a Boolean CONDITION as a parameter, and SHOWS the ERROR dialog if the condition is false. The PROGRAM proceeds without any INTERRUPTION if the condition is true. In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true. |
|
| 100. |
If A Base Class Has A Number Of Overloaded Constructors, And An Inheriting Class Has A Number Of Overloaded Constructors; Can You Enforce A Call From An Inherited Constructor To A Specific Base Constructor? |
|
Answer» Yes, just place a COLON, and then KEYWORD base (parameter LIST to invoke the appropriate CONSTRUCTOR) in the overloaded constructor definition inside the inherited class. Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class. |
|