Friday, 4 January 2008

.NET Interview Questions (3)

Senior Developers/Architects


· What’s wrong with a line like this? DateTime.Parse(myString);
This call doesn’t specify culture information. So a string like ‘12/06/2007’ would be parsed as 06 December 2007 or 12 June 2007 depending on the computer culture setting.

· What are PDBs? Where must they be located for debugging to work?
PDBs are program database files. They contain debugging information for a dll or exe file linking back to the source file.

· What is cyclomatic complexity and why is it important?
Cyclomatic complexity is a software measurement. It is used to measure the amount of decision login within a software module. It is important to measure the complexity of a software module and decide wether refactor a module into smaller ones or not.

· Write a standard lock() plus “double check” to create a critical section around a variable access.
Bool isLocked = false;
If(!isLocked)
{
Lock(lockingObject)
{
If(!isLocked)
{
isLocked = true;
// do something with lockingObject.
isLocked = false;
}
}
}

· What is FullTrust? Do GAC’ed assemblies have FullTrust?
FullTrust is a permission set in .NET framework. There are several predefined permission sets in .net: FullTrust, SkipVerification, Execution, Nothing, LocalIntranet, Internet, Nothing. When FullTrust is granted to a code then the code can access all resources the current user has access to.
GAC assemblies have FullTrust permission set. We can change the permission set of GAC assemblies through .net Configuration Tool.

· What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?
By decorating a method or assembly with security permissions, we can prevent the code from being used in a situation where beyond the permission it requires. And we can fail the code if the permissions it requires are not granted.

· What does this do? gacutil /l | find /i "Corillian" This command lists all assemblies in GAC with the name contains Corillian.

· What does this do? sn -t foo.dll
This command shows the token for the public key in the file foo.dll.

· What ports must be open for DCOM over a firewall? What is the purpose of Port 135?
DCOM uses Port 135 for transmission. Port 135 is to allow client application to locate a DCOM service.

· Contrast OOP and SOA. What are tenets of each? OOP – Application is built on objects, with inheritance, abstraction, polymorphism, encapsulation concepts.
SOA – In SOA we create an abstract layer to define a contract and rules. The client application doesn’t need to know how the service is implemented. The service layer will handle all the details of the implementation.

· How does the XmlSerializer work? What ACL permissions does a process using it require?
XmlSerializer find property values of an object by reflection and output values. ReflectionPermission is required to use it.

· Why is catch(Exception) almost always a bad idea?
This statement hides the error and do nothing about the error. This makes the application development and maintenance very difficult. And we shouldn’t try to catch a generic Exception because we shouldn’t treat system generated fatal errors the same as application generated non-fatal errors.

· What is the difference between Debug.Write and Trace.Write? When should each be used? Debug.Write works on debug mode only. It doesn’t work in a release build. Trace.Write works in both debug and release mode.

· What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?
A debug build contains debugging information for debugging purpose. A release build doesn’t contain debugging information and cannot be debugged. Release build is faster than debug build but the speed difference is not significant.

· Does JITting occur per-assembly or per-method? How does this affect the working set?
Per-method. Methods are not called are not compiled, this reduces the working set.

· Contrast the use of an abstract base class against an interface?
An abstract base class can contains some code but an interface cannot contain code. Abstract classes are useful when some default actions are provided. Classes inherit from an interface must implement all methods.

· What is the difference between a.Equals(b) and a == b?
The first method compares if the value of a and b are equal. The second way checks if the object reference of a and b are the same. For string objects, the second way has the same effect as the first.

· In the context of a comparison, what is object identity versus object equivalence?
Object identity means two objects points to a same memory address. Object equivalence means two objects may point to different memory address but the values in them are equal.

· How would one do a deep copy in .NET?
We can implement the Iclonalbe interface and call Clone() method of an object.

· Explain current thinking around IClonable.
The Clone() method in the IClonable interface doesn’t have a parameter to indicate how the object is cloned. It could be a full value clone or just reference clone depending on how a class is implemented.

· What is boxing?
Take a value type like int in stack and put it to reference type (object) in heap.

· Is string a value type or a reference type?
It’s a reference type.

· What is the significance of the "PropertySpecified" pattern used by the XmlSerializer? What problem does it attempt to solve?

· Why are out parameters a bad idea in .NET? Are they?
An out parameter may be leave as unsigned if the method throws an exception before the parameter is assigned a value.

· Can attributes be placed on specific parameters to a method? Why is this useful?Yes. It’s useful if you want to call COM objects and the types in .net need to be marshalled to types in COM.

No comments: