Thursday, May 12, 2005


C# Interview Questions

The ability to do something does not imply that you can explain it conceptually, or even that you understand the concept of what you are doing. So I have prepared a list of questions\tasks that I think would be useful to complete before going for a C# related job. I have also provided a separate page with questions AND answers for the first set of 173 questions, and another page for the answers to the rest of the questions (not including Scott's questions). You can find the first link below the first set of questions and the second link at the bottom of the post - they are also directly below if you want to jump straight to them.

Before you do the questions, make sure you follow these rules:

Rule 1 - Don't say to yourself "yeah I know that" and move on to the next question. Answer the question as if you were in an interview.

Rule 2 - For the questions that require code - write the code yourself on a piece of paper, don't use an IDE.

The Questions\Tasks:

  1. Name 10 C# keywords.
  2. What is public accessibility?
  3. What is protected accessibility?
  4. What is internal accessibility?
  5. What is protected internal accessibility?
  6. What is private accessibility?
  7. What is the default accessibility for a class?
  8. What is the default accessibility for members of an interface?
  9. What is the default accessibility for members of a struct?
  10. Can the members of an interface be private?
  11. Methods must declare a return type, what is the keyword used when nothing is returned from the method?
  12. Class methods to should be marked with what keyword?
  13. Write some code using interfaces, virtual methods, and an abstract class.
  14. A class can have many mains, how does this work?
  15. Does an object need to be made to run main?
  16. Write a hello world console application.
  17. What are the two return types for main?
  18. What is a reference parameter?
  19. What is an out parameter?
  20. Write code to show how a method can accept a varying number of parameters.
  21. What is an overloaded method?
  22. What is recursion?
  23. What is a constructor?
  24. If I have a constructor with a parameter, do I need to explicitly create a default constructor?
  25. What is a destructor?
  26. Can you use access modifiers with destructors?
  27. What is a delegate?
  28. Write some code to use a delegate.
  29. What is a delegate useful for?
  30. What is an event?
  31. Are events synchronous of asynchronous?
  32. Events use a publisher/subscriber model. What is that?
  33. Can a subscriber subscribe to more than one publisher?
  34. What is a value type and a reference type?
  35. Name 5 built in types.
  36. string is an alias for what?
  37. Is string Unicode, ASCII, or something else?
  38. Strings are immutable, what does this mean?
  39. Name a few string properties.
  40. What is boxing and unboxing?
  41. Write some code to box and unbox a value type.
  42. What is a heap and a stack?
  43. What is a pointer?
  44. What does new do in terms of objects?
  45. How do you dereference an object?
  46. In terms of references, how do == and != (not overridden) work?
  47. What is a struct?
  48. Describe 5 numeric value types ranges.
  49. What is the default value for a bool?
  50. Write code for an enumeration.
  51. Write code for a case statement.
  52. Is a struct stored on the heap or stack?
  53. Can a struct have methods?
  54. What is checked { } and unchecked { }?
  55. Can C# have global overflow checking?
  56. What is explicit vs. implicit conversion?
  57. Give examples of both of the above.
  58. Can assignment operators be overloaded directly?
  59. What do operators is and as do?
  60. What is the difference between the new operator and modifier?
  61. Explain sizeof and typeof.
  62. What does the stackalloc operator do?
  63. Contrast ++count vs. count++.
  64. What are the names of the three types of operators?
  65. An operator declaration must include a public and static modifier, can it have other modifiers?
  66. Can operator parameters be reference parameters?
  67. Describe an operator from each of these categories:
    Logical (boolean and bitwise)
    String concatenation
    Increment, decrement
    Member access
    Delegate concatenation and removal
    Object creation
    Type information
    Overflow exception control
    Indirection and Address
  68. What does operator order of precedence mean?
  69. What is special about the declaration of relational operators?
  70. Write some code to overload an operator.
  71. What operators cannot be overloaded?
  72. What is an exception?
  73. Can C# have multiple catch blocks?
  74. Can break exit a finally block?
  75. Can continue exit a finally block?
  76. Write some try…catch…finally code.
  77. What are expression and declaration statements?
  78. A block contains a statement list {s1;s2;} what is an empty statement list?
  79. Write some if… else if… code.
  80. What is a dangling else?
  81. Is switch case sensitive?
  82. Write some code for a for loop.
  83. Can you have multiple control variables in a for loop?
  84. Write some code for a while loop.
  85. Write some code for do… while.
  86. Write some code that declares an array on ints, assigns the values: 0,1,2 to that array and use a foreach to do something with those values.
  87. Write some code for a collection class.
  88. Describe Jump statements: break, continue, and goto.
  89. How do you declare a constant?
  90. What is the default index of an array?
  91. What is array rank?
  92. Can you resize an array at runtime?
  93. Does the size of an array need to be defined at compile time.
  94. Write some code to implement a multidimensional array.
  95. Write some code to implement a jagged array.
  96. What is an ArrayList?
  97. Can an ArrayList be ReadOnly?
  98. Write some code that uses an ArrayList.
  99. Write some code to implement an indexer.
  100. Can properties have an access modifier?
  101. Can properties hide base class members of the same name?
  102. What happens if you make a property static?
  103. Can a property be a ref or out parameter?
  104. Write some code to declare and use properties.
  105. What is an accessor?
  106. Can an interface have properties?
  107. What is early and late binding?
  108. What is polymorphism
  109. What is a nested class?
  110. What is a namespace?
  111. Can nested classes use any of the 5 types of accessibility?
  112. Can base constructors can be private?
  113. object is an alias for what?
  114. What is reflection?
  115. What namespace would you use for reflection?
  116. What does this do? Public Foo() : this(12, 0, 0)
  117. Do local values get garbage collected?
  118. Is object destruction deterministic?
  119. Describe garbage collection (in simple terms).
  120. What is the using statement for?
  121. How do you refer to a member in the base class?
  122. Can you derive from a struct?
  123. Does C# supports multiple inheritance?
  124. All classes derive from what?
  125. Is constructor or destructor inheritance explicit or implicit? What does this mean?
  126. Can different assemblies share internal access?
  127. Does C# have “friendship”?
  128. Can you inherit from multiple interfaces?
  129. In terms of constructors, what is the difference between: public MyDerived() : base() an public MyDerived() in a child class?
  130. Can abstract methods override virtual methods?
  131. What keyword would you use for scope name clashes?
  132. Can you have nested namespaces?
  133. What are attributes?
  134. Name 3 categories of predefined attributes.
  135. What are the 2 global attributes.
  136. Why would you mark something as Serializable?
  137. Write code to define and use your own custom attribute.
  138. List some custom attribute scopes and possible targets.
  139. List compiler directives?
  140. What is a thread?
  141. Do you spin off or spawn a thread?
  142. What is the volatile keyword used for?
  143. Write code to use threading and the lock keyword.
  144. What is Monitor?
  145. What is a semaphore?
  146. What mechanisms does C# have for the readers, writers problem?
  147. What is Mutex?
  148. What is an assembly?
  149. What is a DLL?
  150. What is an assembly identity?
  151. What does the assembly manifest contain?
  152. What is IDLASM used for?
  153. Where are private assemblies stored?
  154. Where are shared assemblies stored?
  155. What is DLL hell?
  156. In terms of assemblies, what is side-by-side execution?
  157. Name and describe 5 different documentation tags.
  158. What is unsafe code?
  159. What does the fixed statement do?
  160. How would you read and write using the console?
  161. Give examples of hex, currency, and fixed point console formatting.
  162. Given part of a stack trace: aspnet.debugging.BadForm.Page_Load(Object sender, EventArgs e) +34. What does the +34 mean?
  163. Are value types are slower to pass as method parameters?
  164. How can you implement a mutable string?
  165. What is a thread pool?
  166. Describe the CLR security model.
  167. What’s the difference between camel and pascal casing?
  168. What does marshalling mean?
  169. What is inlining?
  170. List the differences in C# 2.0.
  171. What are design patterns?
  172. Describe some common design patterns.
  173. What are the different diagrams in UML? What are they used for?

The answers to these questions can be found here:

Ok, so you've done them and you want more? There's a great list of ASP.NET related interview questions on Scott Hanselman's blog @

He also has another post with general .NET questions @

I'm getting Javascript errors on his blog and IE keeps crashing so I have provided all of his questions below:

First ASP.NET post:

  1. From constructor to destructor (taking into consideration Dispose() and the concept of non-deterministic finalization), what the are events fired as part of the ASP.NET System.Web.UI.Page lifecycle.
  2. Why are they important? What interesting things can you do at each? What are ASHX files? What are HttpHandlers? Where can they be configured?
  3. What is needed to configure a new extension for use in ASP.NET? For example, what if I wanted my system to serve ASPX files with a *.jsp extension?
  4. What events fire when binding data to a data grid? What are they good for?
  5. Explain how PostBacks work, on both the client-side and server-side. How do I chain my own JavaScript into the client side without losing PostBack functionality?
  6. How does ViewState work and why is it either useful or evil?
  7. What is the OO relationship between an ASPX page and its CS/VB code behind file in ASP.NET 1.1? in 2.0?
  8. What happens from the point an HTTP request is received on a TCP/IP port up until the Page fires the On_Load event?
  9. How does IIS communicate at runtime with ASP.NET? Where is ASP.NET at runtime in IIS5? IIS6?
  10. What is an assembly binding redirect? Where are the places an administrator or developer can affect how assembly binding policy is applied?
  11. Compare and contrast LoadLibrary(), CoCreateInstance(), CreateObject() and Assembly.Load().

Second .NET Post (What Great .NET Developers Ought To Know):

Everyone who writes code

  1. Describe the difference between a Thread and a Process?
  2. What is a Windows Service and how does its lifecycle differ from a "standard" EXE?
  3. 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?
  4. What is the difference between an EXE and a DLL?
  5. What is strong-typing versus weak-typing? Which is preferred? Why?
  6. Corillian's product is a "Component Container." Name at least 3 component containers that ship now with the Windows Server Family.
  7. What is a PID? How is it useful when troubleshooting a system?
  8. How many processes can listen on a single TCP/IP port?
  9. What is the GAC? What problem does it solve?

Mid-Level .NET Developer

  1. Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.
  2. Describe what an Interface is and how it’s different from a Class.
  3. What is Reflection?
  4. What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?
  5. Are the type system represented by XmlSchema and the CLS isomorphic?
  6. Conceptually, what is the difference between early-binding and late-binding?
  7. Is using Assembly.Load a static reference or dynamic reference?
  8. When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?
  9. What is an Asssembly Qualified Name? Is it a filename? How is it different?
  10. Is this valid? Assembly.Load("foo.dll");
  11. How is a strongly-named assembly different from one that isn’t strongly-named?
  12. Can DateTimes be null?
  13. What is the JIT? What is NGEN? What are limitations and benefits of each?
  14. How does the generational garbage collector in the .NET CLR manage object lifetime?
  15. What is non-deterministic finalization?
  16. What is the difference between Finalize() and Dispose()?
  17. How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?
  18. What does this useful command line do? tasklist /m "mscor*"
  19. What is the difference between in-proc and out-of-proc?
  20. What technology enables out-of-proc communication in .NET?
  21. When you’re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?

Senior Developers/Architects

  1. What’s wrong with a line like this? DateTime.Parse(myString);
  2. What are PDBs? Where must they be located for debugging to work?
  3. What is cyclomatic complexity and why is it important?
  4. Write a standard lock() plus “double check” to create a critical section around a variable access.
  5. What is FullTrust? Do GAC’ed assemblies have FullTrust?
  6. What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?
  7. What does this do? gacutil /l find /i "Corillian"
  8. What does this do? sn -t foo.dll
  9. What ports must be open for DCOM over a firewall? What is the purpose of Port 135?
  10. Contrast OOP and SOA. What are tenets of each?
  11. How does the XmlSerializer work? What ACL permissions does a process using it require?
  12. Why is catch(Exception) almost always a bad idea?
  13. What is the difference between Debug.Write and Trace.Write? When should each be used?
  14. What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?
  15. Does JITting occur per-assembly or per-method? How does this affect the working set?
  16. Contrast the use of an abstract base class against an interface?
  17. What is the difference between a.Equals(b) and a == b?
  18. In the context of a comparison, what is object identity versus object equivalence?
  19. How would one do a deep copy in .NET?
  20. Explain current thinking around IClonable.
  21. What is boxing?
  22. Is string a value type or a reference type?
  23. What is the significance of the "PropertySpecified" pattern used by the XmlSerializer?
  24. What problem does it attempt to solve?
  25. Why are out parameters a bad idea in .NET? Are they?
  26. Can attributes be placed on specific parameters to a method? Why is this useful?

C# Component Developers

  1. Juxtapose the use of override with new. What is shadowing?
  2. Explain the use of virtual, sealed, override, and abstract.
  3. Explain the importance and use of each component of this string: Foo.Bar, Version=, Culture=neutral, PublicKeyToken=593777ae2d274679d
  4. Explain the differences between public, protected, private and internal.
  5. What benefit do you get from using a Primary Interop Assembly (PIA)?
  6. By what mechanism does NUnit know what methods to test?
  7. What is the difference between: catch(Exception e){throw e;} and catch(Exception e){throw;}
  8. What is the difference between typeof(foo) and myFoo.GetType()?
  9. Explain what’s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?
  10. What is this? Can this be used within a static method?

ASP.NET (UI) Developers

  1. Describe how a browser-based Form POST becomes a Server-Side event like Button1_OnClick.
  2. What is a PostBack?
  3. What is ViewState? How is it encoded? Is it encrypted? Who uses ViewState?
  4. What is the element and what two ASP.NET technologies is it used for?
  5. What three Session State providers are available in ASP.NET 1.1? What are the pros and cons of each?
  6. What is Web Gardening? How would using it affect a design?
  7. Given one ASP.NET application, how many application objects does it have on a single proc box? A dual? A dual with Web Gardening enabled? How would this affect a design?
  8. Are threads reused in ASP.NET between reqeusts? Does every HttpRequest get its own thread? Should you use Thread Local storage with ASP.NET?
  9. Is the [ThreadStatic] attribute useful in ASP.NET? Are there side effects? Good or bad?
  10. Give an example of how using an HttpHandler could simplify an existing design that serves
  11. Check Images from an .aspx page.
  12. What kinds of events can an HttpModule subscribe to? What influence can they have on an implementation? What can be done without recompiling the ASP.NET Application?
  13. Describe ways to present an arbitrary endpoint (URL) and route requests to that endpoint to ASP.NET.
  14. Explain how cookies work. Give an example of Cookie abuse.
  15. Explain the importance of HttpRequest.ValidateInput()?
  16. What kind of data is passed via HTTP Headers?
  17. Juxtapose the HTTP verbs GET and POST. What is HEAD?
  18. Name and describe at least a half dozen HTTP Status Codes and what they express to the requesting client.
  19. How does if-not-modified-since work? How can it be programmatically implemented with ASP.NET?Explain <@OutputCache%> and the usage of VaryByParam, VaryByHeader.
  20. How does VaryByCustom work?
  21. How would one implement ASP.NET HTML output caching, caching outgoing versions of pages generated via all values of q= except where q=5 (as in http://localhost/page.aspx?q=5)?

Developers using XML

  1. What is the purpose of XML Namespaces?
  2. When is the DOM appropriate for use? When is it not? Are there size limitations?
  3. What is the WS-I Basic Profile and why is it important?
  4. Write a small XML document that uses a default namespace and a qualified (prefixed) namespace. Include elements from both namespace.
  5. What is the one fundamental difference between Elements and Attributes?
  6. What is the difference between Well-Formed XML and Valid XML?
  7. How would you validate XML using .NET?
  8. Why is this almost always a bad idea? When is it a good idea? myXmlDocument.SelectNodes("//mynode");
  9. Describe the difference between pull-style parsers (XmlReader) and eventing-readers (Sax)
  10. What is the difference between XPathDocument and XmlDocument? Describe situations where one should be used over the other.
  11. What is the difference between an XML "Fragment" and an XML "Document."
  12. What does it meant to say “the canonical” form of XML?
  13. Why is the XML InfoSet specification different from the Xml DOM? What does the InfoSet attempt to solve?
  14. Contrast DTDs versus XSDs. What are their similarities and differences? Which is preferred and why?
  15. Does System.Xml support DTDs? How?
  16. Can any XML Schema be represented as an object graph? Vice versa?

Had enough yet? Here are some more general .NET questions:

  1. What is MSIL?
  2. What is the CLR and how is it different from a JVM?
  3. What is WinFX?
  4. What is Indigo?
  5. Explain the Remoting architecture.
  6. How would you write an asynchronous webservice?
  7. What is the Microsoft Enterprise Library?
  8. Discuss System.Collections
  9. Discuss System.Configuration
  10. Discuss System.Data
  11. Discuss System.Diagnostics
  12. Discuss System.DirectoryServcies
  13. Discuss System.Drawing
  14. Discuss System.EnterpriseServices
  15. Discuss System.Globalization
  16. Discuss System.IO
  17. Discuss System.Net
  18. System.Runtime contains System.Runtime.CompilerServcies, what else?
  19. Discuss System.Security
  20. Discuss System.Text
  21. Discuss System.Threading
  22. Discuss System.Web
  23. Discuss System.Windows.Forms
  24. Discuss System.XML
  25. Does VS.NET 2003 have a web browser (think about it)?
  26. How are VB.NET and C# different?
  27. Contrast .NET with J2EE.
  28. What benefit do you have by implementing IDisposable interface in .NET?
  29. Explain the difference between Application object and Session object in ASP.NET.
  30. Explain the difference between User controls and Custom controls in ASP.NET.
  31. Describe transaction control in ADO.NET.
  32. Describe transaction control in SQL Server.
  33. In .NET, what is an application domain?
  34. In SQL Server, what is an index?
  35. What is optimistic vs. pessimistic locking?
  36. What is the difference between a clustered and non-clustered index.
  37. In terms of remoting what is CAO and SAO?
  38. Remoting uses MarshallByRefObject, what does this mean?
  39. Write some code to use reflection, remoting, threading, and thread synchronization.

If the interest is high enough I'll publish the answers to the rest of these questions (i.e. Scott's questions) in a future post. Please comment with any extra questions that you think should be added to this list, or any answers for the original 173 that are wrong or incomplete.

Ah, what the hell - here are some more :)

These next questions are taken from:


  1. Can you prevent your class from being inherited by another class?
  2. Explain the three tier or n-Tier model.
  3. What is SOA?
  4. Is XML case-sensitive?
  5. Can you explain some differences between an ADO.NET Dataset and an ADO Recordset? (Or describe some features of a Dataset).


  1. Explain the differences between Server-side and Client-side code?
  2. What does the "EnableViewState" property do? Why would I want it on or off?
  3. What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other?
  4. What base class do all Web Forms inherit from?
  5. What does WSDL stand for? What does it do?
  6. Which WebForm Validator control would you use if you needed to make sure the values in two different WebForm controls matched?
  7. What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control?

Here are some questions from:

  1. What is a satellite Assembly?
  2. In Object Oriented Programming, how would you describe encapsulation?

More questions! This time from:

  1. Can you store multiple data types in System.Array?
  2. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
  3. How can you sort the elements of the array in descending order?
  4. What’s the .NET collection class that allows an element to be accessed using a unique key?
  5. What class is underneath the SortedList class?
  6. Will the finally block get executed if an exception has not occurred?­
  7. Can you prevent your class from being inherited by another class?
  8. If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?
  9. What’s a multicast delegate?
  10. What’s the difference between // comments, /* */ comments and /// comments?
  11. How do you generate documentation from the C# file commented properly with a command-line compiler?
  12. What debugging tools come with the .NET SDK?
  13. What does assert() method do?
  14. What’s the difference between the Debug class and Trace class?
  15. Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
  16. Where is the output of TextWriterTraceListener redirected?
  17. How do you debug an ASP.NET Web application?
  18. What are three test cases you should go through in unit testing?
  19. Can you change the value of a variable while debugging a C# application?
  20. What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
  21. What is the wildcard character in SQL?
  22. Explain ACID rule of thumb for transactions.
  23. Between Windows Authentication and SQL Server Authentication, which one is trusted and which one is untrusted?
  24. What are the ways to deploy an assembly?
  25. What namespaces are necessary to create a localized application?
  26. What is the smallest unit of execution in .NET?

Ok - that's me done - 360+ questions is enough.

The second set of answers can be found at:

This page is powered by Blogger. Isn't yours?