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.
| 1. |
What's The Difference Between <c> And <code> Xml Documentation Tag? |
|
Answer» SINGLE LINE CODE EXAMPLE and multiple-line code example. Single line code example and multiple-line code example. |
|
| 2. |
What's A Satellite Assembly? |
|
Answer» When you WRITE a multilingual or multi-cultural application in .NET, and WANT to DISTRIBUTE the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies. When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies. |
|
| 3. |
What's A Multicast Delegate? |
|
Answer» It’s a delegate that POINTS to and EVENTUALLY fires off SEVERAL methods. It’s a delegate that points to and eventually fires off several methods. |
|
| 4. |
What's The C# Equivalent Of C++ Catch (...), Which Was A Catch-all Statement For Any Possible Exception? |
|
Answer» A catch block that CATCHES the EXCEPTION of type System.Exception. You can ALSO OMIT the parameter data type in this case and just write catch {}. A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}. |
|
| 6. |
What Is The Difference Between Proc. Sent By Val And By Sub? |
|
Answer» BY VAL: changes will not be reflected BACK to the variable. BY VAL: changes will not be reflected back to the variable. |
|
| 7. |
Which Control Cannot Be Placed In Mdi? |
|
Answer» The CONTROLS that do not have EVENTS. The controls that do not have events. |
|
| 8. |
Which Property Of The Textbox Cannot Be Changed At Runtime? |
|
Answer» Locked Property. |
|
| 9. |
What Is The Maximum Size Of The Textbox? |
|
Answer» 65536. 65536. |
|
| 11. |
How Can You Clean Up Objects Holding Resources From Within The Code? |
|
Answer» CALL the dispose METHOD from code for CLEAN up of objects. Call the dispose method from code for clean up of objects. |
|
| 12. |
Describe Ways Of Cleaning Up Objects. |
|
Answer» There is a PERFECT tool provide by .net frameworks calls Garbage collector, where by mean of GC we can clean up the object and reclaim the memory. The namespace used is System.GC the run time will maintain a service called as garbage collector. This service will take care of DEALLOCATING memory corresponding to objects. it works as a thread with least priority. when application demands for memory the runtime will take care of setting the high priority for the garbage collector, so that it will be called for EXECUTION and memory will be released. the programmer can make a CALL to garbage collector by using GC class in system name space. There is a perfect tool provide by .net frameworks calls Garbage collector, where by mean of GC we can clean up the object and reclaim the memory. The namespace used is System.GC the run time will maintain a service called as garbage collector. This service will take care of deallocating memory corresponding to objects. it works as a thread with least priority. when application demands for memory the runtime will take care of setting the high priority for the garbage collector, so that it will be called for execution and memory will be released. the programmer can make a call to garbage collector by using GC class in system name space. |
|
| 13. |
Explain Constructor. |
|
Answer» Constructor is a method in the CLASS which has the same name as the class (in VB.Net its NEW()). It initializes the MEMBER attributes WHENEVER an instance of the class is created. Constructor is a method in the class which has the same name as the class (in VB.Net its New()). It initializes the member attributes whenever an instance of the class is created. |
|
| 14. |
What Are The Two Kinds Of Properties |
|
Answer» TWO TYPES of properties in .Net: GET and Set Two types of properties in .Net: Get and Set |
|
| 15. |
Difference Between Value And Reference Type. What Are Value Types And Reference Types? |
|
Answer» Value type - bool, byte, chat, decimal, DOUBLE, enum , FLOAT, int, LONG, sbyte, SHORT, strut, uint, ulong, USHORT Value type - bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort |
|
| 16. |
Difference Between Imperative And Interrogative Code. |
|
Answer» There are IMPERATIVE and interrogative functions. Imperative functions are the ONE which return a VALUE while the interrogative functions do not return a value. There are imperative and interrogative functions. Imperative functions are the one which return a value while the interrogative functions do not return a value. |
|
| 17. |
Explain Manifest & Metadata. |
|
Answer» Manifest is metadata about assemblies. Metadata is machine-readable information about a RESOURCE, or “”data about data.” In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information. Manifest: Manifest describes assembly itself. Assembly Name, version number, culture, strong name, LIST of all files, Type references, and referenced assemblies. Metadata: Metadata describes contents in an assembly classes, interfaces, enums, STRUCTS, etc., and their CONTAINING namespaces, the name of each type, its visibility/scope, its base class, the nterfaces it IMPLEMENTED, its methods and their scope, and each method’s parameters, type’s properties, and so on. Manifest is metadata about assemblies. Metadata is machine-readable information about a resource, or “”data about data.” In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information. Manifest: Manifest describes assembly itself. Assembly Name, version number, culture, strong name, list of all files, Type references, and referenced assemblies. Metadata: Metadata describes contents in an assembly classes, interfaces, enums, structs, etc., and their containing namespaces, the name of each type, its visibility/scope, its base class, the nterfaces it implemented, its methods and their scope, and each method’s parameters, type’s properties, and so on. |
|
| 18. |
Difference Between A Sub And A Function. |
|
Answer» A Sub does not return anything WHEREAS a Function returns something. -A Sub PROCEDURE is a method will not return a value Sub ShowName(ByVal myName As String) -A function is a method that will return value(s). Function FindSum(ByVal num1 As Integer, ByVal num2 As Integer) As Integer A Sub does not return anything whereas a Function returns something. -A Sub Procedure is a method will not return a value Sub ShowName(ByVal myName As String) -A function is a method that will return value(s). Function FindSum(ByVal num1 As Integer, ByVal num2 As Integer) As Integer |
|
| 19. |
Directcast(123.34,integer) - Should It Throw An Error? Why Or Why Not? |
|
Answer» It WOULD throw an InvalidCast exception as the runtime TYPE of 123.34 (double) DOESNT MATCH with INTEGER. It would throw an InvalidCast exception as the runtime type of 123.34 (double) doesnt match with Integer. |
|
| 20. |
Ctype(123.34,integer) - Should It Throw An Error? Why Or Why Not? |
|
Answer» It WOULD work fine. As the RUNTIME TYPE of 123.34 would be double, and Double can be converted to Integer. the CTYPE(123.34,integer) will work fine no errors. It would work fine. As the runtime type of 123.34 would be double, and Double can be converted to Integer. the ctype(123.34,integer) will work fine no errors. |
|
| 21. |
Why Does Dllimport Not Work For Me? |
|
Answer» All METHODS marked with the DllImport attribute MUST be marked as PUBLIC static EXTERN. All methods marked with the DllImport attribute must be marked as public static extern. |
|
| 22. |
How Can I Access The Registry From C# Code? |
|
Answer» 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: 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: |
|
| 23. |
My Switch Statement Works Differently! Why? |
|
Answer» C# does not support an explicit fall through for case blocks. The following code is not legal and will not compile in C#: C# does not support an explicit fall through for case blocks. The following code is not legal and will not compile in C#: |
|
| 24. |
How Do Destructors And Garbage Collection Work In C#? |
|
Answer» C# has finalizers (similar to destructors except that the RUNTIME doesn't guarantee they'll be called), and they are specified as follows: C# has finalizers (similar to destructors except that the runtime doesn't guarantee they'll be called), and they are specified as follows: |
|
| 25. |
How Do I Create A Delegate/multicastdelegate? |
|
Answer» 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! 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! |
|
| 26. |
Is There An Equivalent To The Instanceof Operator In Visual J++? |
|
Answer» C# has the is OPERATOR: C# has the is operator: |
|
| 27. |
How Can I Get The Ascii Code For A Character In C#? |
|
Answer» Casting the char to an int will give you the ASCII value: char c = 'f'; Casting the char to an int will give you the ASCII value: char c = 'f'; |
|
| 28. |
What Is 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. |
|
| 29. |
What Is The Difference Between A Struct And A Class In C#? |
|
Answer» From language spec: From language spec: |
|
| 30. |
How Do I Convert A String To An Int In C#? |
|
Answer» Here's an example: Here's an example: |
|
| 31. |
Why Do I Get An Error (cs1006) When Trying To Declare A Method Without Specifying A Return Type? |
|
Answer» If you LEAVE off the RETURN type on a method declaration, the compiler thinks you are trying to declare a constructor. So if you are trying to declare a method that RETURNS nothing, use VOID. The following is an example: // This RESULTS in a CS1006 error public static staticMethod (mainStatic obj) // This will work as wanted public static void staticMethod (mainStatic obj) If you leave off the return type on a method declaration, the compiler thinks you are trying to declare a constructor. So if you are trying to declare a method that returns nothing, use void. The following is an example: // This results in a CS1006 error public static staticMethod (mainStatic obj) // This will work as wanted public static void staticMethod (mainStatic obj) |
|
| 32. |
How Can I Get Around Scope Problems In A Try/catch? |
|
Answer» If you try to INSTANTIATE the class inside the try, it'll be out of SCOPE when you try to access it from the catch block. A WAY to get around this is to do the following: If you try to instantiate the class inside the try, it'll be out of scope when you try to access it from the catch block. A way to get around this is to do the following: |
|
| 33. |
How Do I Get Deterministic Finalization In C#? |
|
Answer» In a garbage collected environment, it's impossible to GET true determinism. However, a design pattern that we recommend is implementing IDisposable on any CLASS that contains a critical resource. Whenever this class is consumed, it MAY be placed in a using STATEMENT, as shown in the following example: In a garbage collected environment, it's impossible to get true determinism. However, a design pattern that we recommend is implementing IDisposable on any class that contains a critical resource. Whenever this class is consumed, it may be placed in a using statement, as shown in the following example: |
|
| 34. |
Describe The Accessibility Modifier Protected Internal? |
|
Answer» It is AVAILABLE to DERIVED CLASSES and classes within the same Assembly (and naturally from the BASE CLASS it is declared in). It is available to derived classes and classes within the same Assembly (and naturally from the base class it is declared in). |
|
| 35. |
Why Does My Windows Application Pop Up A Console Window Every Time I Run It? |
|
Answer» Make sure that the target type set in the PROJECT PROPERTIES setting is set to Windows Application, and not CONSOLE Application. If you're using the command line, compile with /target:winexe & not target:exe. Make sure that the target type set in the project properties setting is set to Windows Application, and not Console Application. If you're using the command line, compile with /target:winexe & not target:exe. |
|
| 36. |
Can You Declare The Override Method Static While The Original Method Is Non-static? |
|
Answer» No, you cannot, the signature of the virtual METHOD must REMAIN the same, only the keyword virtual is CHANGED to keyword override. No, you cannot, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override. |
|
| 37. |
Does C# Support C Type Macros? |
|
Answer» 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. 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. |
|
| 38. |
Does C# Support Parameterized Properties? |
|
Answer» No. C# does, however, support the concept of an indexer from language spec. An indexer is a member that enables an OBJECT to be indexed in the same way as an array. Whereas properties ENABLE field-like access, indexers enable array-like access. As an example, consider the Stack class presented earlier. The designer of this class may want to EXPOSE array-like access so that it is possible to inspect or alter the items on the stack without performing unnecessary Push and Pop OPERATIONS. That is, Stack is implemented as a linked list, but it also provides the convenience of array access. Indexer declarations are similar to property declarations, with the main differences being that indexers are nameless (the name used in the declaration is this, since this is being indexed) and that indexers include indexing parameters. The indexing parameters are provided between square BRACKETS. No. C# does, however, support the concept of an indexer from language spec. An indexer is a member that enables an object to be indexed in the same way as an array. Whereas properties enable field-like access, indexers enable array-like access. As an example, consider the Stack class presented earlier. The designer of this class may want to expose array-like access so that it is possible to inspect or alter the items on the stack without performing unnecessary Push and Pop operations. That is, Stack is implemented as a linked list, but it also provides the convenience of array access. Indexer declarations are similar to property declarations, with the main differences being that indexers are nameless (the name used in the declaration is this, since this is being indexed) and that indexers include indexing parameters. The indexing parameters are provided between square brackets. |
|
| 39. |
Does C# Support Templates? |
|
Answer» No. However, there are PLANS for C# to support a type of template KNOWN as a GENERIC. These generic types have similar syntax but are instantiated at RUN time as OPPOSED to compile time. You can read more about them here. No. However, there are plans for C# to support a type of template known as a generic. These generic types have similar syntax but are instantiated at run time as opposed to compile time. You can read more about them here. |
|
| 40. |
Does C# Support #define For Defining Global Constants? |
|
Answer» No. If you want to get something that WORKS like the FOLLOWING C CODE: No. If you want to get something that works like the following C code: |
|
| 41. |
Is It Possible To Have A Static Indexer In C#? |
|
Answer» No. STATIC INDEXERS are not ALLOWED in C#. No. Static indexers are not allowed in C#. |
|
| 42. |
Can I Define A Type That Is An Alias Of Another Type (like Typedef In C++)? |
|
Answer» Not exactly. You can create an alias within a single file with the "USING" directive: using SYSTEM; using Integer = System.Int32; // alias Not exactly. You can create an alias within a single file with the "using" directive: using System; using Integer = System.Int32; // alias |
|
| 43. |
How Do I Port "synchronized" Functions From Visual J++ To C#? |
|
Answer» Original Visual J++ CODE: public SYNCHRONIZED void Run() Original Visual J++ code: public synchronized void Run() |
|
| 44. |
What Is The Difference Between // Comments, /* */ Comments And /// Comments? |
|
Answer» Single-line, multi-line and XML DOCUMENTATION COMMENTS. Single-line, multi-line and XML documentation comments. |
|
| 45. |
Is There Any Sample C# Code For Simple Threading? |
|
Answer» Some sample code follows: using System; Some sample code follows: using System; |
|
| 46. |
Why Do I Get A Security Exception When I Try To Run My C# App? |
|
Answer» Some security exceptions are thrown if you are working on a network SHARE. There are some parts of the frameworks that will not run if being run off a share (ROAMING profile, mapped drives, etc.). To see if this is what's happening, just MOVE the executable over to your local drive and see if it runs without the exceptions. One of the common exceptions thrown under these conditions is System.Security.SecurityException. To get around this, you can change your security POLICY for the intranet zone, code group 1.2, (the zone that running off shared folders falls into) by using the caspol.exe tool. Some security exceptions are thrown if you are working on a network share. There are some parts of the frameworks that will not run if being run off a share (roaming profile, mapped drives, etc.). To see if this is what's happening, just move the executable over to your local drive and see if it runs without the exceptions. One of the common exceptions thrown under these conditions is System.Security.SecurityException. To get around this, you can change your security policy for the intranet zone, code group 1.2, (the zone that running off shared folders falls into) by using the caspol.exe tool. |
|
| 47. |
Does Console.writeline() Stop Printing When It Reaches A Null Character Within A String? |
|
Answer» STRINGS are not null terminated in the runtime, so embedded nulls are allowed. Console.WriteLine() and all similar METHODS continue until the END of the STRING. Strings are not null terminated in the runtime, so embedded nulls are allowed. Console.WriteLine() and all similar methods continue until the end of the string. |
|
| 48. |
From A Versioning Perspective, What Are The Drawbacks Of Extending An Interface As Opposed To Extending A Class? |
|
Answer» With regard to VERSIONING, interfaces are less flexible than classes. With a class, you can SHIP version 1 and then, in version 2, decide to add another method. As long as the method is not abstract (i.e., as long as you provide a default implementation of the method), any EXISTING derived classes continue to FUNCTION with no changes. Because interfaces do not support implementation inheritance, this same pattern does not hold for interfaces. Adding a method to an interface is like adding an abstract method to a base class--any class that implements the interface will break, because the class doesn't implement the new interface method. With regard to versioning, interfaces are less flexible than classes. With a class, you can ship version 1 and then, in version 2, decide to add another method. As long as the method is not abstract (i.e., as long as you provide a default implementation of the method), any existing derived classes continue to function with no changes. Because interfaces do not support implementation inheritance, this same pattern does not hold for interfaces. Adding a method to an interface is like adding an abstract method to a base class--any class that implements the interface will break, because the class doesn't implement the new interface method. |
|
| 49. |
What Is The Difference Between Const And Static Read-only? |
|
Answer» The difference is that static read-only can be MODIFIED by the containing class, but const can never be modified and MUST be initialized to a COMPILE time constant. To expand on the static read-only CASE a bit, the containing class can only modify it: -- in the variable declaration (through a variable initializer). The difference is that static read-only can be modified by the containing class, but const can never be modified and must be initialized to a compile time constant. To expand on the static read-only case a bit, the containing class can only modify it: -- in the variable declaration (through a variable initializer). |
|
| 50. |
Is There A Way Of Specifying Which Block Or Loop To Break Out Of When Working With Nested Loops? |
|
Answer» The EASIEST way is to use goto: The easiest way is to use goto: |
|