While LINQ provides a big umbrella to query in-memory as well as remote collections alike (part of the benefit is having a standard vocabulary to query any collection), there are subtle differences, which rises from the way the two classes of Linq queries work. A Linq query over in-memory collections usually work over the IEnumerable … Continue reading Linq : Significance of AsEnumerable
Category: C#
Pass Property as Expression
I recently needed to pass a property of a class as an expression to a method and read value from it. I found the code that I finally ended up interesting and thought it might be useful to share it here. It might look I could have passed the value directly instead of as an … Continue reading Pass Property as Expression
CLSCompliant Attribute
While developing a library in .Net which could be used by another programming language than it was originally designed in, it is important to remember that the .Net Languages offers a subset of CLR/CTS while offering a superset of CLS. And, if you want to develop a library that could be used by any programming … Continue reading CLSCompliant Attribute
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
A Closer look at DateTime Operations
There are many ways you could round off a DateTime to the nearest Hour. You could create a new Instance of DateTime, ignoring the current instance's Minute/Seconds parts. You could also use the Add Minute method as seen in the following code. Constructor Vs Add Method But which of the two is more efficient ? … Continue reading A Closer look at DateTime Operations
WaitForFirstN Tasks Method
There is a definite gap between TAP Utilities Task.WaitAny and Task.WaitAll. How do we wait for the first 'N' tasks from an array of tasks. That is one utility that is missing from TAP's rich repository. It might not be hard to implement one by yourself though. The above code uses existing Task Collaborators Task.WaitAny … Continue reading WaitForFirstN Tasks Method
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