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.
- 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.
- 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.
- What is a generic?
A generic is a placeholder type. It allows the developer to use an object without immediately determining a typeset. Used primarily in collections.
- What is LINQ?
LINQ(Language Integrated Query) is a methodology for querying data and objects.
- What is a Lambda Expression?
A Lambda Expression is the shorthand syntax for writing LINQ statements.
- 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.
- What is an Abstract Class?
An abstract class is a class that cannot be instantiated. Abstract classes can, however, be inherited.
- What is an Interface?
An interface is a collection of abstract methods.
- 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.
- What are the Access Modifiers?
- 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.
- What is a Constructor?
A constructor is a function that has the same name as its containing class.
- 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.
- What is Deserialization?
Deserialization is the conversion of a byte array into a set object.
- 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.
- 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.
- 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.
- 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.
- What is a sealed modifier?
A sealed modifier prevents the object from being inherited,
- What is Jagged Array?
A jagged array is an array of arrays.
- What is Managed code?
Managed Code is any code executed by the CLR. The code is 'managed' by the .NET Framework.
- 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.
- 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
- 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.
- What are Events?
Events are actions that generate some type of notification.
- 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.
- 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.