.NET Interview Questions
Basic .NET and ASP.NET interview questions
Submitter said questions were asked in a US company hiring a Web developer.
- Explain the .NET architecture.
- How many languages .NET is supporting now? - When .NET was
introduced it came with several languages. VB.NET, C#, COBOL and Perl, etc.
The site DotNetLanguages.Net says
44 languages are supported.
- How is .NET able to support multiple languages? - a language should
comply with the Common Language Runtime standard to become a .NET language.
In .NET, code is compiled to Microsoft Intermediate Language (MSIL for
short). This is called as Managed Code. This Managed code is run in .NET
environment. So after compilation to this IL the language is not a barrier.
A code can call or use a function written in another language.
- How ASP .NET different from ASP? - Scripting is separated from the
HTML, Code is compiled as a DLL, these DLLs can be executed on the server.
- Resource Files: How to use the resource files, how to know which
language to use?
- What is smart navigation? - The cursor position is maintained when
the page gets refreshed due to the server side validation and the page gets
refreshed.
- What is view state? - The web is stateless. But in ASP.NET, the
state of a page is maintained in the in the page itself automatically. How?
The values are encrypted and saved in hidden controls. this is done
automatically by the ASP.NET. This can be switched off / on for a single
control
- Explain the life cycle of an ASP .NET page.
- How do you validate the controls in an ASP .NET page? - Using
special validation controls that are meant for this. We have Range Validator,
Email Validator.
- Can the validation be done in the server side? Or this can be done only
in the Client side? - Client side is done by default. Server side
validation is also possible. We can switch off the client side and server
side can be done.
- How to manage pagination in a page? - Using pagination option in
DataGrid control. We have to set the number of records for a page, then it
takes care of pagination by itself.
- What is ADO .NET and what is difference between ADO and ADO.NET? -
ADO.NET is stateless mechanism. I can treat the ADO.Net as a separate
in-memory database where in I can use relationships between the tables and
select insert and updates to the database. I can update the actual database
as a batch.
^Back to Top
Tough ASP.NET interview questions
- Describe the difference between a Thread and a Process?
- What is a Windows Service and how does its lifecycle differ from a
.standard. EXE?
- What is the maximum amount of memory any single process on Windows can
address? Is this different than the maximum virtual memory for the system?
How would this affect a system design?
- What is the difference between an EXE and a DLL?
- What is strong-typing versus weak-typing? Which is preferred? Why?
- What.s wrong with a line like this? DateTime.Parse(myString
- What are PDBs? Where must they be located for debugging to work?
- What is cyclomatic complexity and why is it important?
- Write a standard lock() plus double check to create a critical section
around a variable access.
- What is FullTrust? Do GAC’ed assemblies have FullTrust?
- What benefit does your code receive if you decorate it with attributes
demanding specific Security permissions?
- What does this do? gacutil /l | find /i “about”
- What does this do? sn -t foo.dll
- What ports must be open for DCOM over a firewall? What is the purpose of
Port 135?
- Contrast OOP and SOA. What are tenets of each
- How does the XmlSerializer work? What ACL permissions does a process using
it require?
- Why is catch(Exception) almost always a bad idea?
- What is the difference between Debug.Write and Trace.Write? When should
each be used?
- What is the difference between a Debug and Release build? Is there a
significant speed difference? Why or why not?
- Does JITting occur per-assembly or per-method? How does this affect the
working set?
- Contrast the use of an abstract base class against an interface?
- What is the difference between a.Equals(b) and a == b?
- In the context of a comparison, what is object identity versus object
equivalence?
- How would one do a deep copy in .NET?
- Explain current thinking around IClonable.
- What is boxing?
- Is string a value type or a reference type?
^Back to Top
Interview questions for Web application developers
The following set was set in by a reader of the site:
Following are the questions from an interview I attended for in C#, ASP.NET,
XML and Sql Server. I will try to add some more as soon as I recollect. Hope
these questions will be useful for people attending interviews in this area.
- What is the maximum length of a varchar field in SQL Server?
- How do you define an integer in SQL Server?
- How do you separate business logic while creating an ASP.NET application?
- If there is a calendar control to be included in each page of your
application, and we do not intend to use the Microsoft-provided calendar
control, how do you develop it? Do you copy and paste the code into each and
very page of your application?
- How do you debug an ASP.NET application?
- How do you deploy an ASP.NET application?
- Name a few differences between .NET application and a Java application?
- Specify the best ways to store variables so that we can access them in
various pages of ASP.NET application?
- What are the XML files that are important in developing an ASP.NET
application?
- What is XSLT and what is its use?
^Back to Top
Interview questions for C# developers
Useful for preparation, but too specific to be used in the interview.
- Is it possible to inline assembly or IL in C# code? - No.
- Is it possible to have different access modifiers on the get/set
methods of a 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.
- Is it possible to have a static indexer in C#? - No. Static
indexers are not allowed in C#.
- 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:
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 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).
- 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 does one compare strings in C#? - 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:
using System;
public class StringTest
{
public static void Main(string[] args)
{
Object nullObj = null; Object realObj = new StringTest();
int i = 10;
Console.WriteLine(\"Null Object is [\" + nullObj + \"]\n\"
+ \"Real Object is [\" + realObj + \"]\n\"
+ \"i is [\" + i + \"]\n\");
// Show string equality operators
string str1 = \"foo\";
string str2 = \"bar\";
string str3 = \"bar\";
Console.WriteLine(\"{0} == {1} ? {2}\", str1, str2, str1 == str2 );
Console.WriteLine(\"{0} == {1} ? {2}\", str2, str3, str2 == str3 );
}
}
Output:
Null Object is []
Real Object is [StringTest]
i is [10]
foo == bar ? False
bar == bar ? True
- 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 you mark a method obsolete? -
[Obsolete] public int Foo() {...}
or
[Obsolete(\"This is a message describing why this method is obsolete\")] public int Foo() {...}
Note: The O in Obsolete is always capitalized.
- How do you implement thread synchronization (Object.Wait, Notify,and
CriticalSection) in C#? - You want the lock statement, which is the same
as Monitor Enter/Exit:
lock(obj) { // code }
translates to
try {
CriticalSection.Enter(obj);
// code
}
finally
{
CriticalSection.Exit(obj);
}
- 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 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.
^Back to Top
C# developer interview questions
A representative of a high-tech company in United Kingdom sent this in today
noting that the list was used for interviewing a C# .NET developer. Any
corrections and suggestions would be forwarded to the author. I won’t disclose
the name of the company, since as far as I know they might still be using this
test for prospective employees. Correct answers are in green color.
1) The C# keyword .int. maps to which .NET
type?
-
System.Int16
-
System.Int32
-
System.Int64
-
System.Int128
2) Which of these string definitions will
prevent escaping on backslashes in C#?
-
string s = #.n Test string.;
-
string s = ..n Test string.;
-
string s = @.n Test
string.;
-
string s = .n Test string.;
3) Which of these statements correctly declares
a two-dimensional array in C#?
-
int[,] myArray;
-
int[][] myArray;
-
int[2] myArray;
-
System.Array[2] myArray;
4) If a method is marked as protected
internal who can access it?
-
Classes that are both in the same assembly and
derived from the declaring class.
-
Only methods that are in the same class as the
method in question.
-
Internal methods can be only be called using
reflection.
-
Classes within the
same assembly, and classes derived from the declaring class.
5) What is boxing?
a) Encapsulating an object in a value type.
b) Encapsulating a copy of an object in a value
type.
c) Encapsulating a value type in an object.
d) Encapsulating a copy
of a value type in an object.
6) What compiler switch creates an xml file
from the xml comments in the files in an assembly?
-
/text
-
/doc
-
/xml
-
/help
7) What is a satellite Assembly?
-
A peripheral assembly designed to monitor
permissions requests from an application.
-
Any DLL file used by an EXE file.
-
An assembly
containing localized resources for another assembly.
-
An assembly designed to alter the appearance
or .skin. of an application.
8) What is a delegate?
-
A strongly typed
function pointer.
-
A light weight thread or process that can call
a single method.
-
A reference to an object in a different
process.
-
An inter-process message channel.
9) How does assembly versioning in .NET prevent
DLL Hell?
-
The runtime checks to see that only one
version of an assembly is on the machine at any one time.
-
.NET allows
assemblies to specify the name AND the version of any assemblies they need
to run.
-
The compiler offers compile time checking for
backward compatibility.
-
It doesn.t.
10) Which .Gang of Four. design pattern is
shown below?
public
class A
{
private A instance;
private A()
{
}
public
static A Instance
{
get
{
if ( A == null )
A = new A();
return instance;
}
}
}
-
Factory
-
Abstract Factory
-
Singleton
-
Builder
11) In the NUnit test framework, which
attribute must adorn a test class in order for it to be picked up by the NUnit
GUI?
-
TestAttribute
-
TestClassAttribute
-
TestFixtureAttribute
-
NUnitTestClassAttribute
12) Which of the following operations can you
NOT perform on an ADO.NET DataSet?
-
A DataSet can be synchronised with the
database.
-
A DataSet can be
synchronised with a RecordSet.
-
A DataSet can be converted to XML.
-
You can infer the schema from a DataSet.
13) In Object Oriented Programming, how would
you describe encapsulation?
-
The conversion of one type of object to
another.
-
The runtime resolution of method calls.
-
The exposition of data.
-
The separation of
interface and implementation.
^Back to Top
.NET deployment questions
- What do you know about .NET assemblies? 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.
- What’s the difference between private and shared assembly?
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.
- What’s a strong name? A strong name includes the name of the
assembly, version number, culture identity, and a public key token.
- How can you tell the application to look for assemblies at the
locations other than its own install? Use the
directive in the XML .config file for a given application.
<probing privatePath=”c:\mylibs; bin\debug” />
should do the trick. Or you can add additional search paths in the
Properties box of the deployed application.
- How can you debug failed assembly binds? Use the Assembly Binding
Log Viewer (fuslogvw.exe) to find out the paths searched.
- Where are shared assemblies stored? Global assembly cache.
- How can you create a strong name for a .NET assembly? With the help
of Strong
Name tool (sn.exe).
- Where’s global assembly cache located on the system? Usually C:\winnt\assembly
or C:\windows\assembly.
- Can you have two files with the same file name in GAC? 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.
- 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?
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.
- What is delay signing? Delay
signing allows you to place a shared assembly in the GAC by signing the
assembly with just the public key. This allows the assembly to
be signed with the private key at a later stage, when the development
process is complete and the component or assembly is ready to be deployed.
This process enables developers to work with shared assemblies as if
they were strongly named, and it secures the private key of the signature
from being accessed at different stages of development.