If at first you don't succeed, call it version 1.0

Contact Me

Sarvesh Kushwaha
Email : sarveshkushwaha@outlook.com

Total Pageviews

Powered by Blogger.

Google+ Followers

Sunday, 29 January 2017

What are Func, Predicate, Action delegates with Examples ? #AspNetInterviewQuestionsSeries


To learn Delegate you guys can refer my previous article. In this article we will learn about what are Func, Predicate and Action Delegate.
Keeping the power of delegates in the mind .Net Framework has introduced the predefined delegates which can be useful for a developer. .Net Framework has also used these predefined delegates at many places e.g LINQ.

Action Delegate: As its name is ACTION this delegate ensures to performs actions and does not return anything. Action Delegate can take upto 16 parameters and returns nothing as they are void delegates and their primary task to perform some action. You can create Action in C# :

// define action 
Action<string> myAction;
// F12 definition will be of your action, it can go upto 16 parameters
public delegate void Action<in T>(T obj);
   


Example : they are most commonly getting used in List<T>.ForEach  like functions.

Friday, 27 January 2017

What are Delegates ? When and why we should use Delegates in C# with example ? #AspNetInterviewQuestionsSeries


Delegates :

Delegate word in English defines that entrust (a task or responsibility) to another person.Same concept is follows in C# with some additional properties.

Delegates Overview :
Delegates have the following properties:

  1. Delegates are similar to C++ function pointers, but are type safe. 
  2. Delegates allow methods to be passed as parameters
  3. Delegates can be used to define callback methods. 
  4. Delegates can be chained together; for example, multiple methods can be called on a single event. 
  5. Used as anonymous methods (inline code). 

Thursday, 26 January 2017

How to acess INTERNAL types and members into another assembly ? #AspNetInterviewQuestionsSeries


Lets learn about INTERNAL keyword in C#. Basically INTERNAL keyword is an access modifier which ensures that types and members within the same assembly. 

But is there any way we can access the INTERNAL  type and members from another assembly? 

yeah there is actually. We can use  the INTERNALVISIBLETO keyword into assmeblyinfo.cs or onto the class at namespace level using System.Runtime.CompilerServices.

Lets Code :

I have created two projects into a solution so we can have two diff assembly.






















Saturday, 21 January 2017

How to implement only few signature of an Interface ? #AspNetInterviewQuestionsSeries


lets make this question situational :) .An interviewer can ask you like this :


Lets suppose i am having an Interface and this Interface consisting five methods signatures.This Interface is already being consumed by our thousand of customer and now new customer came and asked that we need only three method inside that. what will you do to resolve this situation or what will you suggest to your customer ? 

Possible solutions are to this situation are as follows :

  1. Implement that Interface using an Abstract class and mark those methods as abstract which you don't want to implement.
  2. If class should be concrete then you can implement rest of the functions and throw exceptions like  NotImplementedException or NotSupportedException .
  3. Last you can segregate that Interface further into two interface and implement those in class.But then in above scenario it will become a tough situation.

Friday, 20 January 2017

How you can limit a class to create only two instances ? #AspNetInterviewQuestionsSeries


How you can limit a class to create only two(n) instances ?


This is one of my favorite question in an interview.So before watching the answer take a minute and think how you can create a such class .. tough ? Ahan its very easy.

 Answer : The basic idea is create a static property and increment that in constructor every time you are creating an object of that class. And throw an exception when that count is greater than two.

next question which can be ask is :