C# 11 Features – Auto-default Struct
Tech Xposer
by saikk
1y ago
Before understanding these new changes to Struct type, will do some understanding of the background of this implementation. At compile time, the compiler will attempt to take your code that initializes a given field and put it in a parameterless constructor. A constructor is essentially a function that is invoked when a structure is constructed.   Structures implicitly derive from System.ValueType. The System.ValueType superclass implements a default constructor that subclasses cannot override. This means that it is not physically possible to explicitly ..read more
Visit website
C#11 features – Required Members
Tech Xposer
by saikk
1y ago
A new keyword required is introduced in C# 11 where it will be decorated to the instance property and field declaration within a class/record/struct. Whenever a class is declared with a property or field with the required keyword, the caller is forced to initialize in the object initializer scope. In the above example, when the caller tries to create the Employee object, the compiler throws an error to initialize the required properties. The following line is a valid object initialization in this case.  Employee employee = new() { FirstName = "Sai", LastName = "Kumar" }; &nbs ..read more
Visit website
C#11 features – Raw String Literals
Tech Xposer
by saikk
1y ago
Raw String Literals are the new format of string literals introduced since C# 11. This new format can help us in getting the output string with any arbitrary text like new lines, spaces, and special characters without any special sequences.  Earlier, for example, if we need to maintain an email template with huge text with multiple lines and special characters including placeholders need to replace with at runtime before sending the email to the end user. To achieve this requirement, we need to follow some indirect approaches like maintaining these text as part of external embedded files ..read more
Visit website
C# code performance improvement with Span Type
Tech Xposer
by saikk
1y ago
A new structure Span<T> was introduced since C# 7.2. The main goal of it is to avoid allocating new objects on heap memory when working with the contiguous region of arbitrary memory requirements.  By using Span<T>, the following are a couple of advantages we may see  Avoid allocating memory on the Heap for the new objects created. Less call to the GC process and which improves the performance as this CPU time can be used for the actual process. Also, no need to manage non-allocated objects. Example to understand how Span<T> can give better performance&n ..read more
Visit website
Understanding Task vs ValueTask
Tech Xposer
by saikk
1y ago
These days most of the Interfaces we are seeing with methods have a return type as ValueTask. So, through this article, we are going to understand What is ValueTask? How it is different from Task? and when do we need to use ValueTask? Before addressing the above questions, we will deep dive into the below method. public async Task<List<Employee>> GetEmployees() { if(_EmployeeCache == null) { _EmployeeCache = await _employeeRepo.GetEmployees(); return employees; } else ..read more
Visit website
Understanding Thread Starvation in .NET Core Applications
Tech Xposer
by saikk
2y ago
Most of the applications will be facing a performance issue while scaling and this might be due to thread starvation. Before getting into the thread starvation problem, we need to understand how the thread pool works. Thread Pool is a thread management or thread queueing mechanism for Dotnet. On the hardware level, we will be having a set of CPUs and x2 processors, for example, if we have hardware of 4 cores and it will accommodate 8 logical processors. Each processor will execute one thread at any given time. For this article let assume we are working with 8 logical processors. This is how th ..read more
Visit website
Working with Async/Await/Task keywords in depth
Tech Xposer
by saikk
2y ago
Modern systems are coming more powerful with multiple processors. Similarly, the modern server application development also improved to leverage the host CPU power for processing multiple requests in parallel to achieve more scalability. Earlier we have many limitations on asynchronous calls and not utilizing the complete CPU cores. The Task Parallel Library (TPL) that was introduced in the .NET Framework 4 made rapid changes to our asynchronous development and utilization of infrastructure. Still, most of the developers are not much familiar with understanding these keywords and doing regular ..read more
Visit website
Understanding worker thread and I/O Completion Port (IOCP)
Tech Xposer
by saikk
2y ago
Every .NET/.NET Core application is associated with a thread pool and is a collection of threads that effectively executes asynchronous calls of an application. These threads on the thread pool are known as Worker threads. These are worker threads are further divided logically into two types, one is worker threads which are used to process CPU-intensive logic i.e., it mostly used CPU to execute its logic like any calculations, etc.., and another is I/O threads, these threads are used to perform I/O requests or time-consuming requests such as read/write to file system, calling Database or calli ..read more
Visit website
Working with Smarter Enums in C#
Tech Xposer
by saikk
2y ago
Enum means enumeration i.e., mentioning things one by one, and enum type is a special data type that enables a variable to be a set of predefined constants. Below is the sample which demonstrates a simple use of Enum in regular development. public enum Vehicles { CAR, BIKE, VAN } Here in the above sample, we declared Vehicle enum where we have a set of vehicle types. Now, in our business logic, we can use these enum constants to represent vehicle type and get the constant name as well the integer value of the order (by default will start with 1). Now if we need to get the average pr ..read more
Visit website
Consume OData feed with C# Client Application
Tech Xposer
by saikk
4y ago
Introduction OData represents Open Data Protocol is an OASIS standard initiated by Microsoft in the year 2007. This defines the best practices for the consumption of data and building with quarriable REST APIs. The difference between Odata and REST API is, Odata is a specific protocol and REST is an architectural style and design pattern. Using REST we can request and get data using HTTP calls. OData is a technology that uses REST to consume and build data. Expecting readers of this article having some knowledge on Odata query. But, to make a simple understanding. This protocol gives the power ..read more
Visit website

Follow Tech Xposer on FeedSpot

Continue with Google
Continue with Apple
OR