ttmind

Main Content

Please wait...

For loop in C#

For loop is control statement. It is a keyword used for repetitive execution of statement. For loop executes a block of statements repeatedly until the specified condition returns true/false value. It is one of the easiest loop and mostly used. The syntax of for loop is for(variable declaration/initialization; condition; steps(increment/decrement)) { //statements } Flowchart of for loop Variable declaration= integer type. Example: int i; int j; Initialization = the beginning value ......Read More

Recursive Function in C# and its Example

A function which calls itself or is in a potential cycle of function calls For Example: Scenario: An Evens number is an integer whose digits are all even. For example 2426 is an Evens number but 3224 is not. Write a function named isEvens that returns 1 if its integer argument is an Evens number otherwise it returns 0. The function signature is int isEvens (int n). Solution: using System; namespace evenNumber { class Program { static void Main(string[] args) { ......Read More
C# cannot run more than one main method at a time in a single file. Main method is also the entry point to the application. But it is syntatically ok to define more than one main method in your application in a single namespace with different class name. So, we have to provide the entry point to be compiled before we can run the desired main method of our choice. For example we have a single C# file with multiple class and main method like given below Now to run the required class we ......Read More
When to use switch instead of if statements? If your code needs to compare many possible conditions of an expression where the expression itself is non-trivial. If your code contains many values that may need the same code. If your code contains some values that essentially require all of another value's execution, only including few statements. When to Use if instead of switch statements? If you are testing the truthiness of an expression. If your code only has a single confirm ......Read More

How to use Result filters in ASP.NET Core MVC?

Result filter can run code immediately before and after the execution of individual action results. They run only when the action method has executed successfully. They are useful for logic that must surround view or format execution. As the diagram shows the order of execution in the MVC execution pipeline, Implement either the IResultFilter or IAsyncResultFilter interface. Their execution surrounds the execution of action results. A difference between IResultFilter & IActionFilter w ......Read More
In ASP.NET Core MVC we have the option to filter Exceptions in MVC execution pipeline, and it's handy too, for developer as we know when it comes no one like, so having an option to handle it seems interesting, in ASP.NET framework also we have the option to handle it, but as we are focusing on ASP.NET Core MVC in this post, let's see some important note on Exception filter. What is Exception filter? A custom class where we can write our logic to execute on action method execute in ASP. ......Read More
As with name indicate this Resource filter can be used for handling Resources and helps to ShortCircuit if required in the execution pipeline. Resource filters are the first to handle a request after authorization. They can run code before the rest of the filter pipeline, and after the rest of the pipeline has completed. Resource filter is useful to implement caching or otherwise short-circuit the filter pipeline for performance reasons. It runs before model binding, so it can influence mod ......Read More
Authorization filters are a special filter in ASP.NET Core MVC, Which has 3 main property are, Control access to action methods. Are the first filters to be executed within the filter pipeline. Have a before method, but no after method. We only write a custom authorization filter if we are writing our own authorization framework. Do not throw exceptions within authorization filters. In any application Authorization is critical and in ASP.NET Core MVC we have the option to Authorize an ......Read More
ASP.NET Core MVC allows us to run code before or after specific stages in the request processing pipeline, It has different Filters but in this article scope, we are focusing on only one Filter that is ActionFilters. We discus bout other Filter in a different article. In ASP.NET Core MVC if we need to have common code for all the actions to Filter request or we can say if we need some block of code which will run on every request then we have ActionFilters and we can use them for cross-cutting ......Read More
So, what we are doing in ASP.NET Core 2.2 is there is a new tool which name is “httprepl”. It’s a dotnet core global tool that you can install in your machine and that gives you a command line repl for interacting with API endpoints. Let’s install it from the command line: dotnet tool install -g --version 2.2.0-* --add-source https://dotnet.myget.org/F/dotnet-core/api/v3/index.json dotnet-httprepl If you have already installed then, you can verify it with the followi ......Read More