The need for creating an Empty array/collection rises quite often in most applications. This, normally presents us with two options. Using the Constructor, new T[0]; Using the extension method, Enumerable.Empty Let's dive a bit deeper into both and examine how both these options work and differ. Using new T[0] Creating an empty array with Array … Continue reading Enumerable.Empty vs new T[0]
Category: C#
Linq Join on Like%
One of the recent requirements I came across recently needed what looks like a Join on a 'Like%'. Let me cite an example to demonstrate the requirement. Consider the Collections below. Master Collection ID Name 1 Jia Anu 2 Sreena Anu 3 Anu Viswan Child Collection ID First Name Age 1 Jia 2 3 Sreena … Continue reading Linq Join on Like%
Caliburn.Micro #008: Gesture Recognition using Short-Hand Syntax
In this part of Caliburn.Micro tutorials we would explore how to configure and use Gesture Recognition with Caliburn.Micro, particularly exploiting the Short-Hand syntax for Actions. Caliburn.Micro doesn't support this out of the box, so obviously we need to work around the Actions to provide support for Gestures. Let's first formulate the syntax of how we … Continue reading Caliburn.Micro #008: Gesture Recognition using Short-Hand Syntax
Filter List and Display Type members with specified attribute
One of the recent questions that was intriguing (for me) in Stackoverflow was the need to Process a List and while displaying the result, display only the properties that are decorated with a specific attribute. Let me explain with an example. Consider the following Entity. For a List<Employee>, the expected result would display only "BusinessVertical", … Continue reading Filter List and Display Type members with specified attribute
Assignment using Ternary Operator
Couple of days back, I happened to come across a question in StackOverflow. Question seemed pretty straightforward, but at the same time, interesting. How would one use ternary operator for assignment. For example, how would write following code using ternary operator. Obviously, following wouldn't work. One way to use ternary operator would using Action. But … Continue reading Assignment using Ternary Operator
C# 8.0 : Default Implementation of Interface Members
The way C# language is evolving is definitely exciting and one feature that truly makes the wait for C# 8.0 all the more exciting is default implementation of interfaces. Since the onset, interfaces were behaviors characterized by member signatures, strictly disallowing any implementation. All that is going to change when C# 8.0 rolls out, as … Continue reading C# 8.0 : Default Implementation of Interface Members
Early Exceptions for Iterator and async Methods
One of the first things you would need to be vary of while working with Iterator methods and async methods is exception handling. Both Iterator methods and async methods delay the execution of your code, right until you need the result, but it also results in delayed exceptions. Late Exception With Iterator Methods Let's consider … Continue reading Early Exceptions for Iterator and async Methods
Allocation free ‘async’ Methods
Task Asynchronous Programming (TAP) model will go down as one of the landmark of C# language revolution. The typical method signature with return type Task/Task<T> has since then made significant appearances in our programming life. But despite all its glorious functionalities, it needs to be noted that it comes at a certain cost - performance … Continue reading Allocation free ‘async’ Methods
Updated Span API : NonPortableCast and AsReadOnlySpan to MemoryMarshal.Cast and AsSpan
One of the interesting changes (not sure why Microsoft changed this) was moving/changing the Span<T> API's a bit. For example, the Span<T>.NonPortableCast Method was moved as an extension method under MemoryMarshal. Previous API Current API Similarly, the string.AsReadonlySpan method has been renamed. The new API is as follows. Previous API Current API The MemoryMarshal extensions … Continue reading Updated Span API : NonPortableCast and AsReadOnlySpan to MemoryMarshal.Cast and AsSpan
The new String Interpolation and Ternary Operator
A quick tip for the new C# string interpolation. The new string interpolation has made things more simpler and readable. One might be tempted to include ternary operators within string interpolation. However if you attempt something like following, the compiler would throw an error The fix is as simple as it can get. Just include … Continue reading The new String Interpolation and Ternary Operator