.NET Interview Questions 2015

This series of articles will present you what you will be asked in your next .NET job interviews in 2015.

In general it gives an overview of the concepts of Object Oriented Programming which you WILL be asked:

1. Abstract class
– It is intended to be a base class.
– Cannot be instantiated.
– Can contain abstract methods and properties
o They don’t have implementation and must be implemented in the derived class, by overriding the method/property
o Methods are implicitly virtual
o Cannot use static or virtual modifiers with combination of abstract
– Can contain non abstract methods
2. Interface – express behavior that a class/struct may choose to support
– Cannot be instantiated
– Can contain methods, properties, events
– All of the methods are public and abstract
– One class can derive one base class and many interfaces
3. Method overriding and method overloading
– Method overriding is implementing base class method in the derived class
– Method overloading is having one method with different list of parameters.
4. Boxing/unboxing
– Boxing is converting a value type object to the type of object or to any interface implementing this value type. It wraps its value inside a System.Object and stores it in the managed heap. Unboxing extracts the value type from the object. Boxing is implicit, unboxing is explicit. This concept is used because of the C# unified type system, that any type can be treated as an object.
In general it is expensive process, because a new object must be allocated and constructed.
5. Static constructor
– A given class may define only a single static constructor. In other words, the static constructor cannot be overloaded.
– A static constructor does not take an access modifier and cannot take any parameters.
– A static constructor executes exactly one time, regardless of how many objects of the type are created. This is done before any other instance level constructors.
– It can be used to initialize static properties of the class
6. Generics
– Introduced in .NET version 2.0.
– Design classes and methods that rely on specific type.
– Allow code reuse, type safe, performance
– Mostly used for collections
– If not used generics, in order to have generalization, reference type are upcasted to Object and value types are boxed. This comes to a cost of decreased performance and additional memory used.
7. Stack memory, Stack overflow
– Keeps track of what is being called, functions. Every time a new function is called, it is positioned on top of the stack. Memory is allocated for its parameters. If they are value types they are copied, if they are reference type, pointers to them are copied. You can access only the last one e.g. the top one. After it finishes execution is removed and the function below goes on.
– Stack has limited memory, if overfilled overflow exception is thrown
– Value types are stored on the stack
– Stack automatically allocates and later deletes memory, needed for execution
– If a reference type is needed in a function, it is created on the heap and a pointer to it is stored in the stack.
– In multithreaded environment, every thread has its own stack, but all of them share the same heap.
8. Heap memory
– Keeping track of the objects – reference types are stored on the heap
– Anything can be accessed any time
– Objects left without references are cleaned by the Garbage Collector
– Heap memory can be extended
9. Memory cleaning
– GC runs and cleans objects from the managed heap, which don’t have references pointing to them
– Not managed resources (files, db connections, network connections). There is a finalization queue. Object’s finalizer is invoked, then it is garbage collected. However better practice is to explicitly clean/close these resources (IDisposable). The keyword using is relevant to this interface. When using it, after leaving the scope of the “using” block, dispose method is called.
– Weak reference – creates a reference to an object, but this object can be garbage collected at any time. That’s why this has to be checked if the reference IsAlive, before using it.
10. Object methods
– ToString() – returns string representation of the object
– Equals() – determines whether the specified object is equal to the current one
– GetHashCode() – A hash code is a numeric value that is used to identify an object during equality testing. It can also serve as an index for an object in a collection.
– GetType() – Gets the type of the current object
11. Serialization
12. Immutable
13. Events

14. Thread Pool – form of multithreading where, tasks are added to a queue and automatically started when threads are created
15. GAC – assemblies are added in order to be reused/shared between apps. They have to be signed and strongly named for security reasons. Allows you to have different versions of the same assembly. Use gacutil.exe in order to manipulate the GAC.
16. Multicast delegate – they let you invoke multiple methods.
17. .NET Remoting
a. Singleton call – gets one instance for all incoming request. Every variable used will be shared between all request.
b. Single call – every request will get a new instance of the defined type, it’s own memory and variables. Still can share static and global variables external resources etc.

1. Web Farms / Load balancer – load balancer is used to spread the request between the servers in the web farm in order to prevent overloading of one server. When using this approach it’s important to define where Session is stored. Session can be stored in three places:

a. InProc (in the server’s memory) – if a user sends the first request to Server A, his session is created and stored in the memory of that server. However, if later user’s request is sent to Server B, his session won’t be available and big mess will happen. So if we want to use InProc session, we need to configure the load balancer to use Sticky Sessions. This means that all request for specific session are always sent to the same server. In general this is not a good approach.

b. SQLServer session – all session data is stored in one central place. However, all session data, saved in the DB, must be serialized. Better approach for heavy session data.

c. State Server – data is stored in a separate server in one central place. It will be handled by Windows Service (aspnet_state). All session data must be serialized.

d. machine.config – this file needs to be the same on all of the servers in the farm, because encryption (of the view state) is using the Machine Key value and it must be the same on all of the servers.

Stay tooned for next topic covered!

Leave a Reply

Your email address will not be published. Required fields are marked *