C# – Execute function based on input type

It is probably interesting to many junior programmers to create different functions and to execute them, based on the code. In short something like:

However, the things become more interesting, when we have different input types. Then the above algorithm can be also applied, but we need a little more code for it. This is not the case, when we simply name four different functions with one name (in the example – VitoshAcademy) and we give different argument types to the different function. Then the Main code will call the function for which it has arguments.

The code looks like this:

We see that in the Main part of the code we declare two strings (o & s). These two strings are arguments in the Function “VitoshAcademy”. Thus, from the four possibilities, listed above we will get the one, which has two strings as arguments.

At the end, we will get “2 Strings” as a result, displayed at the console.

Enjoy the code 🙂