Interview questions for C# developers
-
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:
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).
-
Is it possible to inline assembly or IL in C# code? - No.
-
Is it possible to have a static indexer in C#? - No. Static indexers are not allowed in C#.
-
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? - 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: [return-type] foo(out int o) { }
-
How do you directly call a native function exported from a DLL? -
-
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 in the documentation.
-
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.
-
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.
Recent Posts
- Interview Questions Decoded, Part 2
- Interview Questions Decoded, Part 1
- Explain the ways of authentication techniques in ASP.NET
- What is Authentication in ASP.NET?
- Describe how the ASP.NET authentication process works
- How to save data from dataset?
- How to use performance monitor to diagnose bottlenecks in your application?
- What are the various objects in Dataset?
- Describe the basic schema of a .config file.
- Aren’t XML, SGML, and HTML all the same thing
Tag Cloud
-
application
ASP
assembly
career
class
code
company
constructor
control
Database
difference
Don
employer
file
hiring manager
information
interview
interviewer
job
job seekers
language
manager
method
NET
page
person
position
Process
question
quot
response
salary
Serialization
Server
State
string
system
table
time
type
user
way
web
work
XML