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
Tag: C# 7.x
C# 7.3 Features : Tuple Comparison & Generic Constraints
C# 7.3 is another minor roll-out that brings along with 'seemingly minor' improvement, but ones that definitely opens new opportunities. In this blog post, we will explore two features that are introduced in 7.3 Tuple Comparison C# 7.x had already made tuple an immensely powerful tool with a variety of features, and the latest minor … Continue reading C# 7.3 Features : Tuple Comparison & Generic Constraints
Type Casting using Span<T>
In an earlier post, we explored the possibilities of Span and performance benefits of the feature was clearly visible in our benchmark tests. We will continue exploring the Span further in this post, as attempt to cast between types using Span. The cast functionality is not that hard, thanks to the extension methods that comes … Continue reading Type Casting using Span<T>
Deconstructing Non-Tuples
The 'Tuple evolution' in C# 7x has created increased possibilities of C# like never before, both in terms of performance as well as readability. One of the nicest feature that came along has been the Deconstruction of tuples. Deconstructing Tuples The tuple data structure allows us to bundle together a finite number of values without … Continue reading Deconstructing Non-Tuples
Nominal Vs Structural Type System
Anonymous Types and Tuples might look very similar, but there is one significant difference which separates them. As always, nothing can be more explanatory than writing code. Consider the above code. What could be the output ? Are both false or are both true ? Interestingly, the output is as follows. Though syntactically similar, both … Continue reading Nominal Vs Structural Type System
Benchmarking Span<T> Performance
Span<T> is yet another addition to C# 7.x and is particularly useful in developing memory intensive applications. So what is Span all about ? As Microsoft describes it, Span<T> is a new value Type which enables the representation of contiguous regions of arbitrary memory, regardless of whether the memory is associated with a managed … Continue reading Benchmarking Span<T> Performance
Ref Value Type
In an earlier post, we discussed the readability factor of the reference semantics, mentioning how it kind of makes the code less readable. However, that doesn't take away the big door of opportunities the new features add. Consider the following scenario. Now, prior to C# 7, this was difficult. There was no way we could … Continue reading Ref Value Type
Reference Semantics and Code Readability
One of the features Microsoft packed with C# 7.2 is Reference Semantics with Value Types. Though designed with the intention to improve performance by eliminating the need for copying (and thereby allocating memory) value types , I do have my reservations on the complexity it adds to readability of code for a programmer. Let's consider … Continue reading Reference Semantics and Code Readability