Category: C#

LINQ improvements in .NET 6

The Default Value for *OrDefault Methods The Enumerable.FirstOrDefault method returns the first element of a sequence, or a default value if no element is found. In .NET 6, you can override the default value. You can override the default value also for SingleOrDefault and LastOrDefault methods. New *By Methods .NET 6 introduces the new Enumerable.By* methods. A ‘keySelector’ is provided to compare

Global Exception Handling in .NET 6

Exception handling is one of the most critical areas in modern web application development. If exceptions are not handled properly, the whole app can be terminated, causing severe issues for users and developers. In this article, I will discuss different methods of global exception handling in .NET apps. Error handling with try-catch blocks Try-catch blocks

Singleton vs Static Class

Singleton and Static classes can only have one instance available in memory, and both classes can be used to maintain the global state of an application, however, there are many differences between them. In this article, I explain what their differences are. Singleton Singleton is one of the creational patterns from “Gang of Four” (GoF), and

Cross Site Scripting update for ASP.Net 4.5

Introduction to XSS Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications that enables attackers to inject client-side script into web pages viewed by other users. A cross-site scripting vulnerability may be used by attackers to bypass access controls such as the same origin policy. Cross-site scripting carried out

Parallel Processsing with Threads Introduction

C# supports parallel execution of code through multithreading. A thread is an independent execution path, able to run simultaneously with other threads. A C# client program (Console, WPF, or Windows Forms) starts in a single thread created automatically by the CLR and operating system (the “main” thread), and is made multithreaded by creating additional threads.