Blog

How to Find the Maximum Value of an Array in C#

How to Find the Maximum Value of an Array in C#

In this article, we will discuss different ways How to find the maximum value of an array in C# and after that also find the best way to perform this task. As a programmer, we perform this task more often so we must know the best way to get high performance. Let's start with the examples and explanations. If you want to boost your productivity as a .NET Developer follow the below link. Click Me. Create an array: To perform this task we first have to create a predefined array so we can operate on this array. var sampleArray =…
Read More
How To Post Data In ASP.NET Using AJAX  Form Serialization

How To Post Data In ASP.NET Using AJAX Form Serialization

Welcome to mycodebit. When we work with ASP.NET (Core) MVC we have to submit the forms through razor pages so, in this article, we discuss How To Post Data In ASP.NET Using AJAX Form Serialization. I'm using visual studio 2019 for this tutorial. If you have not created the project yet please follow this link to create a new project. Steps: Let's first create a model that we will use to submit the form data and we will create this model class as per our requirement to transfer data. public class SubmitPersonalInfo { public string Name { get; set; }…
Read More
Multiple Cases of Switch Expression for Same Result in C#

Multiple Cases of Switch Expression for Same Result in C#

Welcome to mycodebit.com. In this article, we will discuss Multiple Cases of Switch Expression for same result in C# that have the same results. We will combine cases in switch statements in relational patterns and constant patterns. In the relational pattern we will compare expression results to the constant and with the constant pattern, we will test if the constant is equal to the expression result. If you want to increase your productivity as a .NET developer check this post. Click Me I have listed some examples to understand techniques to combine case statements. Ordinary Switch Statement to get Same Results:…
Read More
How to Create PDF Document in ASP.NET Core 6 Web API

How to Create PDF Document in ASP.NET Core 6 Web API

Welcome to mycodebit.com.In this article we will learn How to Create PDF Document in ASP.NET Core 6 Web API. This is a very common task that we face daily as an ASP.NET Core web developer. In this post, I'm using Visual Studio 2022 and .NET version 6.0. You can download the complete source code from here. Let's start with the practical. Create a new Project: To create a new project first open visual studio and click on "create a new project". After that select "ASP.NET Core Web API" as a project template. Configure Project: Configure the project setting after project…
Read More
How to improve ASP.NET Core 6 Web API Performance

How to improve ASP.NET Core 6 Web API Performance

Welcome to the post; today, we will discuss How to improve ASP.NET Core 6 Web API Performance. We have summarised vital factors that can efficiently improve ASP.NET Core Web API performance. Let's discuss the points. 1- Minimize allocations of large objects: In ASP.NET Core apps, the default garbage collector removes the allocations and releases the memory automatically. So we developers do not have to worry about garbage collection, and how and when the memory is freed. But the issue is a garbage collector takes a lot of CPU time to clean unreferenced objects from memory, huge objects. Because large objects…
Read More
How to write string to file in C#

How to write string to file in C#

In this article, we are going to discuss how to write string to file in C#. There are multiple ways to do this task but firstly we will discuss static convenience methods on the System.IO.File class to write IEnumerable<string> and a string to a text file. How write array of strings in file in C#: using System.IO; using System.Threading.Tasks; class demo { public static async Task ExampleAsync() { string[] lines = { "dummy line 1", "dmmy line 2", "dummy line 3" }; await File.WriteAllLinesAsync("WriteLines.txt", lines); } } In the above example, we are writing the array of strings after creating a file…
Read More
Save Activity Log in ASP.NET Core Web API like a Pro

Save Activity Log in ASP.NET Core Web API like a Pro

In Any Web Application activity logs are the most important and common thing. Today we will learn how can we save activity log in ASP.NET Core Web API project. There are many ways to perform this task but we are going to discuss one of the efficient ways with you. We will keep record of activity logs by overriding our savechanges() and savechangesasync() method. Tools: For this project, I’m using Visual studio community 2019, windows os, and .NET Core Version 5. Let’s Start: To save logs we have to create a table in our database. Create a class and name…
Read More
Logging Exceptions in ASP.NET Core Web API

Logging Exceptions in ASP.NET Core Web API

Logging Exceptions in ASP.NET Core is a very important thing even in any web application. When we have a lot of users on our application so it will be very easy for us to track the exception and solve this by simply checking the exception records. We do not have to test a lot to find the error. In this tutorial, we will learn how we can log errors into our database in the ASP.NET Core Web API project. Tools: We are using Visual Studio Community 2019, .NET Core version 5, and MSSQL Database. Lets start: To add exception logs…
Read More
How to throw Custom Exceptions in ASP.NET Core Web API

How to throw Custom Exceptions in ASP.NET Core Web API

We can handle our errors/exceptions by simply using try-catch blocks. But What if we have to throw custom exceptions on some error. To achieve this custom exception throw approach follow the below-mentioned tutorial. Custom exception handling and throwing custom exceptions is very important to maintain a standard Web Application. It will create a difference and your code will look more clean and standard. In this post, we are going to learn that how can we throw custom exceptions in our ASP.NET Core Web API project.  Tools: Visual Studio Community 2019 Windows OS Let’s get started: If we have to throw…
Read More