Posts

Primary Constructors in C# 12

Introduction C# 12 introduces a new feature called Primary Constructors. This feature aims to simplify the initialization of properties in classes, especially for classes with many properties. In this article, we'll explore Primary Constructors and see how it work. Before dive into Primary Constructors, let's take a quick look at how class constructors work in C#. In C# constructor is a special method that is called when an object of a class is created. Constructors are used to initialize the state of an object, which typically involves setting the values of the class properties. Here's an example of a typical class with a constructor in C#: public class Employee { public string FirstName { get; set; } public string LastName { get; set; } public DateTime HireDate { get; set; } public decimal Salary { get; set; } public Employee(string firstName, string lastName, DateTime hireDate , decimal salary) { FirstName = firstName; LastNa

ControllerBase class in asp.net core

A SP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, internet-connected applications. One of the core building blocks of an ASP.NET Core application is the ControllerBase class, which serves as the base class for controllers that handle HTTP requests.   What is the ControllerBase class? The ControllerBase class is a base class for controllers in ASP.NET Core that handles HTTP requests. It provides a set of common properties and methods that are used by controllers to handle HTTP requests and generate HTTP responses. The ControllerBase class does not implement any specific behavior or logic, but instead provides a set of common methods and properties that can be used by derived classes. The ControllerBase class is defined in the Microsoft.AspNetCore.Mvc namespace, and is part of the ASP.NET Core MVC framework. It is derived from the Controller class, and provides a simpler, lighter-weight alternative for building APIs and microser

Raw String Literals In C# 11

  What is C# 11.0? C# 11.0 is the latest version of the C# language. Features Raw string literals Generic math support Generic attributes UTF-8 string literals etc Introduction Raw string literals in C# 11 are a new feature for developers to create strings that are easier to read and write and manipulate. Raw string literals comprise a sequence of characters enclosed in double quotes, but the 'at' character (@) comes before the opening quotes, making them readable even if they contain special characters or spaces. Traditional strings In traditional strings, special characters like the newline (\n) or the tab (\t) must be represented by escape sequences. If you wanted to create a string that contains the word "Hello" followed by a newline character, you would typically write: string message = "Hello\nWorld" ; C# Copy Raw string literals With raw string literals, using special characters like the traditional method is no longer necessary. Using raw string li