Scott Hanselman's interview questions - Senior Developers/Architects

Answers to Senior Developers/Architects
  1. What’s wrong with a line like this? DateTime.Parse(myString);

    Parse converts date at any cost. What if user passes date in format MM/dd/yyyy whereas you are expecting in dd/MM/yyyy.Assume the user is passing 12/09/2006 meaning Dec 12, 2006, whereas Parse (based on the current locale) picked it up as Sep 12, 2006. The result is not something which you would like. Also Parse takes more time compared to other as it has to check for a gazillion formats. Instead if you know the format its better to go with ParseExact. Then why the hell do we have Parse? May be for the old VB customers it was an easier transition. Chec out more here or here
  2. What are PDBs? Where must they be located for debugging to work?

    A Program DataBase file (extension .pdb) is a binary file that contains type and symbolic debugging information gathered over the course of compiling and linking the project. A PDB file is created when you compile a C/C++ program with /ZI or /Zi or a Visual Basic, Visual C#, or JScript program with the /debug option. The Visual Studio debugger uses the path to the PDB in the EXE or DLL file to find the project.pdb file. If the debugger cannot find the PDB file at that location, or if the path is invalid, for example, if the project was moved to another computer, the debugger searches the path containing the EXE followed by the symbol paths specified in the Options dialog box (Solution Properties-->Debug Symbol Files node in VS.NET 2003). The debugger will not load a PDB that does not match the binary being debugged.
  3. What is cyclomatic complexity and why is it important?

    This calls for a separate entry in itself.!30862CF919BD131A!581.entry
  4. Write a standard lock() plus “double check” to create a critical section around a variable access.

    This calls for a separate entry in itself.!30862CF919BD131A!582.entry
  5. What is FullTrust? Do GAC’ed assemblies have FullTrust?

    Full Trust Permission Set Grants unrestricted permissions to system resources. My_Computer_Zone code group by default has has FullTrust permission. This can be changed using CASPOL.exe though.
  6. What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?

    Allows administrators to see exactly which permissions your application needs to run, using PermView
    Prevents your code from being exploited beyond what permissions it absolutely needs
    Allows your application to forcibly fail instead of having to manually handle situations where it might be denied permissions it requires.
    More info can be found here / here
  7. What does this do? gacutil /l | find /i "Corillian"

    gacutil /l lists the assemblies in GAC. Find /i lists all the assemblies which have Corillian in their identity. (/i ignores case I suppose).
  8. What does this do? sn -t foo.dll

    Extracts the publick key token from the strongly named assembly foo.dll
  9. What ports must be open for DCOM over a firewall? What is the purpose of Port 135?

    135 is used by Windows RPC. HKEY_LOCAL_MACHINE\Software\Microsoft\Rpc\Internet (Key) Ports (Multi Line String Value) specifies what other ports will be open.
  10. Contrast OOP and SOA. What are tenets of each?

    OOP Tenets - Abstraction, Encapsulation, Inhertiance, Polymorphism. SOA Tenats - (PEACE) - Policy based negotiation, Explicitness of boundaries, Autonomy, Contract Exchange Differences: Read this nice analogy. This is as best as it can get
  11. How does the XmlSerializer work? What ACL permissions does a process using it require?

    The XmlSerializer creates a temporary assembly with two types named XmlSerializationReader1, XmlSerializationWriter1 which derive from XmlSerializationReader and XmlSerializationWriter classes. These types are responsible for DeSerializing and Serializing respectively. The XMlSerializer constructors caches the assemblies emitted if you use one of these constructors
    Its recommended to use these. So the account under which host process is running must have Write, Delete permissions on the temporary directory. This the user profile temp directory for windows applications and the app specific folder under Temporary ASP.NET Files (in the framework directory) for ASP.NET applications
  12. Why is catch(Exception) almost always a bad idea?

    When you catch an exception, you’re stating that you expected this exception, you understand why it occurred, and you know how to deal with it. In other words, you’re defining a policy for the application. However, you shouldn’t catch Exception because a StackOverflowException or OutOfMemoryException exception could be thrown at any time. Hiding these fatal problems and allowing the application to continue running will cause unpredictable results.
  13. What is the difference between Debug.Write and Trace.Write? When should each be used? Debug.Write is compiled into a release build. Trace.Write gets compiled irrespective of the build configuration chosen. Trace is useful for production debugging (can be turned on off based on config at various levels / severity). Debug is useful for development environment debugging.
  14. What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?

    • A debug build generates a file containing debug symbols (.pdb); a release build does not.
    • A debug build generates extra instructions to accomodate the debugger (e.g. NOP instructions to assist your setting breakpoints); a release build does not include these.
    • A release build uses full optimizations when compiling which might include rearranging your code or inlining it for efficiency, a debug build doesn't do this.
    • A debug build allocates extra memory on the heap for objects to facilitate detecting memory overwrite errors; a release build doesn't do this.
    • A release build will thus be smaller, faster, and more efficient than a debug build.
    More Info -4704-94f6-0efda4a44465
  15. Does JITting occur per-assembly or per-method? How does this affect the working set?

    Per-method. Since methods which are not called are not compiled at all, this reduces the working set.
  16. Contrast the use of an abstract base class against an interface?!30862CF919BD131A!576.entry
  17. What is the difference between a.Equals(b) and a == b?

    Cannot be answered unless you have the variable declarations for a and b.
    The default implemenation for Equals on object checks for references or identity.
    There is no default implementation for '==' on value types.
    The default implementation for '==' on reference types checks for idenity or memory references
    More here

  18. In the context of a comparison, what is object identity versus object equivalence?

    identity comparison: check if both the instances point to the same memory address.
    equivalence: two instances are considered equal if their values represented by them are equal, they can point to different memory locations. For example:
    Person p1 = new Person();
    p1.age = 25;
    Person p2 = new Person();
    p2.age = 25;

    identity comparison of p1 and p2 should return false whereas equivalence should return true.
  19. How would one do a deep copy in .NET?

    Serialize / DeSerialize is an option, but it has a performance impact and required all the objects to be serializable.
    ICloneable is another.
  20. Explain current thinking around IClonable.

    Because the interface contract does not specify the type of clone performed, different classes have different implementations. A consumer cannot rely on ICloneable to let them know whether an object is deep-cloned or not. May be I would use something like ICloneableEx with ShallowCopy and DeepCopy as members. Read more here
  21. What is boxing?!30862CF919BD131A!349.entry

  22. Is string a value type or a reference type?

    String is a reference type. But being immutable it gives the illusion of a value type.
  23. What is the significance of the "PropertySpecified" pattern used by the XmlSerializer? What problem does it attempt to solve?

    Nillable value types. condiitonal serialization of fields using the Property specified pattern.

  24. Why are out parameters a bad idea in .NET? Are they?

    Out parameters can be abused however. As a matter of good programming style if you find yourself writing a method with many out parameters then you should think about refactoring your code. One possible solution is to package all the return values into a single struct. /default.aspx
    .Net doesn't verify that an out parameter is set inside a method that uses an out parameter before an exception is called. This mean that you may use an uninitialized parameter without the compiler catching on to this. Use ref parameters instead.
  25. Can attributes be placed on specific parameters to a method? Why is this useful?

    Yes. Best example is MarshalAs attribute used for PInvoke.


Other C# interview question

Comments are closed.