.NET Interview Questions - Part 1

August 07, 2007 • 9:52AM • permalink
With MANY open .NET development positions in the Media Department, I've had many opportunities to refine my interview process. Below is a summary of my experience, including some of the general .NET questions we ask most job candidates at Demand Media (and why). Since we are constantly refining the interview process and adding new questions and since this is going to be a rather long entry, I'll split it up into several separate posts.


General Interview Notes


First, a couple of general caveats:

1) I try to give the interviewee the benefit of the doubt. A lot of the time, the people I talk to have more years of experience than I've been alive, so I understand that a lot of them are intimidated by my youth.

2) Look up something about the company on the Internet. Of course nobody has time to redo their entire resume to cater to a specific company, but look up something about the company and try to tune your responses to items that might relate.

3) Most interviews I've been on included the question: "Do you have any questions for me?" That's your cue. Ask any intelligent question without appearing to be a snob, but make sure you ask something (besides your compulsory question about which snacks are kept in which kitchen.) A few stand-by questions I used to use are: "Will I be able to continue my personal education and learn here?", "How quickly do you adapt to new technologies and upgrades to existing technologies?", "What is the team dynamic like?" and "How much room is there for career growth at XXXXXXX Company?"

4) Your resume is your first impression. Use it as a way to highlight your strengths, not as a laundry list of items you "used once in school". There are two main items in particular I see all the time: C++ and .NET 3.5 - usually only by candidates who can't explain ANY intricate features of either.

5) An interview should be a learning process, as well. If you don't understand a question or an answer to a question, ask!

6) TURN OFF YOUR CELL PHONE!!! For many people I've encountered during my career (including me), a cell phone going off during an interview is an instant death sentence. You can start juggling keyboards after that - it's not going to matter...

And now finally...


.NET Questions


1) Describe the difference between a reference type variable and a value type variable?

This is a good question we use to get rid of the riff-raff right away. If you can't form some semblence of an answer to this question, we won't even consider you a candidate for a job.

While we look for many keywords, a simple description of the fact that a value type stores the actual value of the data and the reference type stores an address or pointer to the data usually suffices.

If you don't somehow relate the reference and value types to their storage location on the stack and the heap, that will definitely become question 1b.


2) Describe the process of using an integer variable (of any size) as a bitmap for boolean flags?

This is a process I brought with me to Demand (inherited from Intermix Media, where I propagated the idea as well), but I think it's fairly clear why this is a simple, but vital idea. (Although, I'm assuming below a basic knowledge of binary numbers and bitwise mathematics.)

The idea is that any number can be viewed as a series of bytes and then bits. First I'll describe the process, then I'll demonstrate it in both basic C/C++/C# code and then using .NET additions.

As you should already know, any number can be represented in binary form, which means any number can be represented as a sum of one or more powers of two. We can show this number a number of ways:

123 (decimal) OR

(100 * 1) + (10 * 2) + (1 * 3) OR

(10^2 * 1) + (10^1 * 2) + (10^0 * 3) OR

(64 * 1) + (32 * 1) + (16 * 1) + (8 * 1) * (4 * 0) + (2 * 1) + (1 * 1) OR

(2^6 * 1) + (2^5 * 1) + (2^4 * 1) + (2^3 * 1) * (2^2 * 0) + (2^1 * 1) + (2^0 * 1) OR

1111011 (binary)


If the above binary number is extended to represent a 32-bit int,it would look like:

00000000000000000000000001111011

with the leftmost bit being bit 31 and the rightmost bit being bit 0.

This allows us to see the above as a series of 32 switches or Boolean (True/False) flags that can be accessed (counting from 0 and from the right) by taking a bitwise AND of the number and the "on" value.

As you can see from the above representation, the fourth bit from the right is in the 2^3 position. So, if we take the bitwise AND of our value with 2^3 (8), we get the following:

= 123 & 8
= 8

Since the result (8) is the same as the flag (8), the integer (123) does contain the flag!


When adding flags into your integer, you instead use the bitwise OR. This is always used to switch flags on, so if the flag already exists in your number - it will have no effect, as shown in the following examples:

= 123 | 8
= 123


= 123 | 4
= 127


Finally, to remove a class you take the bitwise AND of the bitwise NOT of the value you're trying to remove. The bitwise NOT inverts the value, so the AND masks any other bits that are currently set, like:

= 127 & (~4)
= 123



The example I usually like to use is to build out the character classes in an RPG-like setting.

Simple C-style Example:


/* CC_ is for Character Class */

int CC_DWARF = 1;
int CC_FIGHTER = 2;
int CC_NINJA = 4;
int CC_SAMURAI = 8;
int CC_ELF = 16;
int CC_MAGICIAN = 32;
int CC_PALADIN = 64;
int CC_HOBBIT = 128;
int CC_PRIEST = 256;
int CC_DARKLORD = 1073741824;


int character_dwarf_fighter = CC_DWARF | CC_FIGHTER;
//value is 3


int character_samurai_elf = CC_SAMURAI | CC_ELF;
//value is 24


int super_crazy_bad_guy = CC_FIGHTER | CC_NINJA | CC_SAMURAI | CC_MAGICIAN | CC_DARKLORD;
//value is 1073741870



//let's remove the CC_DARKLORD class

int super_crazy_bad_guy2 = super_crazy_bad_guy;
super_crazy_bad_guy2 &= ~(CC_DARKLORD);
//value of super_crazy_bad_guy2 is now 46
//OR CC_FIGHTER | CC_NINJA | CC_SAMURAI | CC_MAGICIAN


//let's check super_crazy_bad_guy2 for CC_DARKLORD

if ((super_crazy_bad_guy2 & CC_DARKLORD) == CC_DARKLORD)
   Response.Write("This guy is nothing now!");
//this will print...



//let's check super_crazy_bad_guy2 for CC_DARKLORD

if ((super_crazy_bad_guy2 & CC_PRIEST) == CC_PRIEST)
   Response.Write("This guy is holier than I am!");
//this will NOT print...




Simple .NET/C#-style Example:


[Flags]
public enum CharacterClasses : int
{
   Dwarf = 1,
   Fighter = 2,
   Ninja = 4,
   Samurai = 8,
   Elf = 16,
   Magician = 32,
   Paladin = 64,
   Hobbit = 128,
   Priest = 256,
   DarkLord = 1073741824
};



CharacterClasses super_crazy_bad_guy = CharacterClasses.Fighter | CharacterClasses.Ninja | CharacterClasses.Samurai | CharacterClasses.Magician | CharacterClasses.DarkLord;
Response.Write(super_crazy_bad_guy.ToString());
//prints Fighter, Ninja, Samurai, Magician, DarkLord


super_crazy_bad_guy -= CharacterClasses.DarkLord;
Response.Write(super_crazy_bad_guy.ToString());
//prints Fighter, Ninja, Samurai, Magician


super_crazy_bad_guy |= CharacterClasses.Elf;
Response.Write(super_crazy_bad_guy.ToString());
//prints Fighter, Ninja, Samurai, Elf, Magician


if ((super_crazy_bad_guy &= CharacterClasses.Elf) != 0)
   Response.Write("An elf!");
   
//this will print



if ((super_crazy_bad_guy &= CharacterClasses.Paladin) != 0)
   Response.Write("A paladin!");
   
//this will NOT print





.NET Quickies

* What is the root class that all other .NET classes are derived from?
System.Object

* Name as many ways as you can think of to find a certain character in a string?
String.Contains, "Character Crawl" using any of (for/foreach, String.Chars, String.CharAt, String[], bit masking, plus many others), String.IndexOf, String.LastIndexOf, etc.

* What is a GUID?
Global Unique IDentifier - A 128-bit value that is statistically impossible to be duplicated in a closed environment. (Bonus points if you throw in a note about using it in a multi-server environment by setting the machinekey, generating on the SQL server, using a Key server, etc.)


More to come! Also, if anyone has any suggestions for questions that I should add into my interview process, please send me them!



Showing 2 of 2 comments
     


This definitely highlights the need for a [code] block for the blogs...

Nevermind. :)

Register or Login to rate or post a comment on this blog entry.




Tags

SQL Server 2000 math VB csharp concurrency API SQL type query operator mathematics Remote Desktop functional programming CosplayWar enhancements module launch OOP c sharp Python Erlang reflection Stopwatch anime Adam help Microsoft Generic Method optimization performance AnimeConPics Regular Expressions PC Immutable String c SQL Server OS Mikomicon lazy initialization c plus plus IIS Javascript script generation PHP protocol interview interface JSP software open source

Links