C# Interview Questions

These questions are generic C# questions I've run across, with a smattering of OOP principles that translate across any similar languages.

  1. What are the four tenets of an OOP language?
    Abstraction- refers to hiding the internal operations of a class from anything that consumes that class.
    Encapsulation- refers to the bundling of data and methods into a single object or class
    Inheritance- refers to the ability of one class to use properties of another class
    Polymorphism- refers to the ability to use different object types through the same interface.

  2. What is boxing and unboxing?
    Boxing is the ability to store a value type into an object.  
    Unboxing is the ability to take an object variable and convert it to a specific value type.

  3. What is a generic?
    generic is a placeholder type. It allows the developer to use an object without immediately determining a typeset. Used primarily in collections.

  4. What is LINQ?
    LINQ(Language Integrated Query) is a methodology for querying data and objects.

  5. What is a Lambda Expression?
    Lambda Expression is the shorthand syntax for writing LINQ statements. 

  6. What are delegates?
    Delegates allow the developer to set variables as function calls. It can be thought of as to a pointer to a function.

  7. What is an Abstract Class?
    An abstract class is a class that cannot be instantiated. Abstract classes can, however, be inherited.

  8. What is an Interface?
    An interface is a collection of abstract methods.

  9. What is the difference between overloading and overriding?
    Overloading - multiple functions of the same name, using different input parameters.
    Overriding - use of a subclass to override(replace) the method functionality of a main class.

    Overloading is a static binding, while overriding is a dynamic binding.

  10. What are the Access Modifiers?

  11. What is the difference between Public, Static and Void?
    Public - the object or method is available to anything able to consume it.
    Private - the object is available only to the class that contains it.
    Static- the object is globally accessible without instantiating a class. 

  12. What is a Constructor?
    constructor is a function that has the same name as its containing class.

  13. What is Serialization?
    Serialization  is the act of turning an object into a stream of bytes. This stream can then be stored into another platform (like a file.)

    A class can be made serializable by declaring it as ISerialize.

  14. What is Deserialization?
    Deserialization is the conversion of a byte array into a set object.

  15. What's the difference between Read-Only variables and Constant variables?
    Constant variables are set once during compile time and cannot be changed. Read-Only variables are used only when setting a value at runtime.

  16. Can you override the methods in an interface?
    No. All of the interface methods are virtual, so they can only be overridden in the class that inherits them.

  17. What is the difference between a Struct and a Class?
    A Struct is a value-type variable, where a Class is a reference type.  Structs cannot be inherited, and are stored on the stack for speed of access.

  18. What is the difference between Stack and Heap memory?
    Heap memory is managed by the application.
    Stack memory is more structured and managed by the system.
    Value types are allocated to the Stack.
    Reference types are allocated to the Heap.

  19. What is a sealed modifier?
    sealed modifier prevents the object from being inherited, 

  20. What is Jagged Array?
    jagged  array is an array of arrays.

  21. What is Managed code?
    Managed Code is any code executed by the CLR. The code is 'managed' by the .NET Framework.

  22. What are the different types of classes in C#?
    Keyword: Partial Class - A 'shared' class allows its members to be used by multiple .cs files.
    Keyword: Sealed class - A class that cannot inherited. To access its members, you need to instantiate the class directly.
    Keyword: Abstract class - A class that cannot be instantiated. This class can only be inherited, and will contain at least one method.
    Keyword: Static class - A class that does not allow inheritance. Members of a static class are also static.

  23. What are the steps taken in C# code compilation?
    1. Compiling the source code to Managed Code
    2. Combining newly created code to Assemblies
    3. Loading the Common Language Runtime (CLR)
    4. Executing the assembly by the CLR

  24. What's the difference between a Virtual Method and an Abstract Method?
    Abstract Method - always has a default implementation. It can be overridden in its derived class, though not necessarily mandatory. It can be overridden using the keyword: override.
    Virtual Method - does not have an implementation, and resides in the abstract class. It is mandatory that the the derived class implements the abstract method.

  25. What are Events?
    Events are actions that generate some type of notification.

  26. What's the difference between a signed and an unsigned variables?
    A signed variable is one that can be expressed as a positive or negative number. An unsigned number can only be expressed to the positive.

  27. What's the difference between a checked and an unchecked operator?
    A checked operator is one that instructs the runtime to generate an OverrflowException error rather than 'eating' the error when an integral-typed expression exceeds the arithmetic limits of that type.

This is where THE END begins.