C# – Why you should never use the checked keyword – Unless absolutely necessary

So, some of you may not know about this keyword at all, but at one point in your life you may find out and feel that it will be useful to use it when you are doing mathematical operations in your code. Let’s start by discussing what this keyword provides. According to Microsoft documentation, the checked keyword is provided to explicitly enable arithmetic overflow for integer mathematical operations. In the past we have discussed how arithmetic overflows can cause problems and unexpected outcomes from our code. A prime example we mentioned is why Ghandi was a nuclear asshole in Civilization Continue reading C# – Why you should never use the checked keyword – Unless absolutely necessary

C# Multithreaded Resource access – Concurrent Collections


Concurrent collections are a feature added in .Net 4.0 and allow developers to create thread safe collections without worrying as much as they had to worry with Generic Collections.
They do not remove any possible concern the developer should have while working with resources that are accessed from multiple threads, but removes many of the common ones.

Continue reading C# Multithreaded Resource access – Concurrent Collections

C# Multithreaded Resource Access – Locks, Monitors and Mutex

C# provides us many ways to safely handle shared resources from than one threads/tasks. In this blog post we will discuss some of the different types that exist (and they are many), the different programming patterns they are used for, their benefits and their drawbacks.

Continue reading C# Multithreaded Resource Access – Locks, Monitors and Mutex

C# 7: What are discards and how to use them

Let’s assume that you wish to call a method that has a return value and also accepts an out variable, but you do not wish to use the contents of the out variable that will be returned.
So far we were creating a dummy variable that will later not be used, or discarded.
With C# 7 you can now use Discards

Continue reading C# 7: What are discards and how to use them

C# Typecasting: Use ‘as’ instead of the normal Cast

csharpWe are all used to casting from one type to another in different languages that we use. In all C-like languages (C,C++,C#,Java etc) we use this simple format.

Okay I am using an overly trivial example here but I think you get the point.

Now imagine the following example. We are given an enumerable formĀ of data through the network, in JSON format let’s say, We are aware that this enumerable has different forms of data, some are objects, some are strings, some are ints etc. Bear with me here, I know this is a crazy scenario which has no meaning but let’s suspend our disbelief for a moment and go through with it. So let’s say we have the following Enumerable

Continue reading C# Typecasting: Use ‘as’ instead of the normal Cast