Q No.1 :-  What is the difference between Reflection and dynamic keyword in C#?


There are 4 great differences between Dynamic and reflection. Below is a detailed explanation of the same. Reference

Point 1. Inspect VS Invoke

Reflection can do two things one is it can inspect meta-data and second it also has the ability to invoke methods on runtime.While in Dynamic we can only invoke methods. So if i am creating software’s like visual studio IDE then reflection is the way to go. If i just want dynamic invocation from the my c# code, dynamic is the best option.


Point 2. Private Vs Public Invoke

You can not invoke private methods using dynamic. In reflection its possible to invoke private methods.

Point 3. Caching

Dynamic uses reflection internally and it also adds caching benefits. So if you want to just invoke a object dynamically then Dynamic is the best as you get performance benefits.

Point 4. Static classes

Dynamic is instance specific: You don’t have access to static members; you have to use Reflection in those scenarios.

Q No.2 :- What is the yield keyword used for in C#?


Yield has two great uses

  1. It helps to provide custom iteration with out creating temp collections.
  2. It help to do stateful iteration.

Below is a simple video which i have created with full demonstration in order to support the above two points

Q No.3 :- FizzBuzz C# interview questions


I think you started with a complicated way. Improving that code would be more complicated. You can use a temp variable to track and display that variable at the end of the FizzBuzz check. Below is code and you can also watch this detail c# FizzBuzz youtube video ( ) which explains how the below code is implemented.

 for (int j =  1; j <= 100; j++)
  string  Output = "";

  if (j % 3 == 0) Output =  "Fizz";// Divisible by 3 --> Fizz

  if (j % 5 == 0)  Output += "Buzz"; // Divisible by 5 --> Buzz

  if (Output ==  "") Output = j.ToString(); // If none then --> number

  Console.WriteLine(Output); // Finally print the complete output

Q No.4 :-
Difference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio?


Build solution :- Compiles code files ( DLL and Exe) which are changed.

Rebuild :- Deletes all compiled filed and Compiles them again irrespective if the code has changed or not.

Clean solution :- Deletes all compiled files ( DLL and Exe).

You can see this youtube video ( ) where i have demonstrated the differences and below are visual representation which will help you to analyze the same in more detail.


Just adding more to this answer the difference between Rebuild vs ( Clean + Build) because there seems to be some confusion around this as well.

The difference is the way the build and clean sequence happens for every project. Let’s say if your solution has two projects “proj1” and “proj2”. If you do a rebuild it will take “proj1” , clean ( delete) the compiled files for “proj1” and build it. After that it will take the second project “proj2” , clean compiled files for “proj2” and compile “proj2”.

But if you do a “clean” and build”. It will first delete all compiled files for “proj1” and “proj2” and then it will build “proj1” first followed by “proj2”.


Q No.5 :- How do I mark a method as Obsolete/Deprecated?


As said by every one you can mark it by using the [Obsolete] attribute.Below is a simple youttube video which explains all 3 variations of Obsolete attribute.

Click to see c# Obsolete attribute video

Q NO.6 :- resolving circular dependencies with dependency injection


DI is a overkill for circular dependency. You can just add a interface between those classes and it should work out.

I have demonstrated the solution of how interfaces can remove dependency in this 10 minutes youtube video Avoiding Circular dependency using interfaces

Q No.7 :- When should you use Async Controllers in ASP.NET MVC?


I know this is a old question but i struggled to get the answer , so heres my two cents.

Its like saying that if we do not have fever , should i still take a pill. You should use Asynch controller if you see thread starvation on your web server. IIS webserver maintains a pool of threads. So when any request comes in he picks up the thread from thread pool. If at a given moment all the threads from the pool are utilized and request comes in. That request goes in a waiting mode , this situation is termed as “Thread starvation”. You can also watch this youtube video where i have demonstrated how MVC thread starvation looks like


When you make your controller as Asynch , it utilizes the thread spawns the operation and moves that thread back to the thread pool so that it can utilized for other requests which comes to the MVC application. Once the operation finishes he pulls back the thread from thread pool and displays the view.

Q No.8 :- Do asynchronous operations in ASP.NET MVC use a thread from ThreadPool on .NET 4


First thing its not MVC but the IIS who maintains the thread pool. So any request which comes to MVC or ASP.NET application is served from threads which are maintained in thread pool. Only with making the app Asynch he invokes this action in a different thread and releases the thread immediately so that other requests can be taken.

I have explained the same with a detail video ( “MVC Asynch controllers and thread starvation” ) which shows how thread starvation happens in MVC and how its minimized by using MVC Asynch controllers.I also have measured the request queues using perfmon so that you can see how request queues are decreased for MVC asynch and how its worst for Synch operations.

Q No.9 :- Parallel.ForEach vs Task.Factory.StartNew


I did a small experiment of running a method “1000000000” times with “Parallel.For” and one with “Task” objects.

I measured the processor time and found Parallel more efficient. Parallel.For divides your task in to small work items and executes them on all the cores parallely in a optimal way. While creating lot of task objects ( FYI TPL will use thread pooling internally) will move every execution on each task creating more stress in the box which is evident from the experiment below.

I have also created a small video which explains basic TPL and also demonstrated how Parallel.For utilizes your core more efficiently as compared to normal tasks and threads.

Experiment 1

Parallel.For(0, 1000000000, x => Method1());

Experiment 2

for (int i = 0; i < 1000000000; i++)
Task o = new Task(Method1);


Q No.10 :-  C# difference between `==` and .Equals()


If its a object type then “==” compares if the object references are same while “.Equals()” compares if the contents are same.

If its a string object then it does content comparison , irrespective you either use “.Equals()” or you use the “==” operator.

See the below youtube video which actually demonstrates the same.

Q No.11 :- Real world use cases for C# indexers?


Heres a video i have created and below is a detailed explanation about the same.

Indexers helps to access contained collection with in a class using a simplified interface. It’s a syntactic sugar.

For instance lets say you have a customer class with addresses collection inside it. Now let’s say we would like to like fetch the addresses collection by “Pincode” and “PhoneNumber”. So the logical step would be that you would go and create two overloaded functions one which fetches by using “PhoneNumber” and the other by “PinCode”. You can see in the below code we have two functions defined.

Customer Customers = new Customer();

If you use indexer you can simplify the above code with something as shown in the below code.

Customer Customers = new Customer();
Address o = Customers[10001];
o = Customers["4320948"];


Q No.12:- Regex to extract string between 2 different characters and strings

You can watch the below youtube regular expression video , i am sure the above question you can answer it yourself.

Q No.13 :- Confused about SQL XML datatype


If you want to store in SQL Server better use the XML data type as you get advantage of checking the type with XSD schema.

QNo. 14 :- What is the difference between ++i and i++

i++ :- In this scenario first the value is assigned and then increment happens.

++i :- In this scenario first the increment is done and then value is assigned

Below is the image visualization and also here is a nice practical video ( which demonstrates the same.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s