One of the big new features introduced with C# 7 is the ValueTuple.
Now we all know Tuples, we heard of their existence in C#, saw them in a tutorial and decided not to use them, ever again because they were completely awkward and difficult to use.
Continue reading Understanding C# 7 ValueTuples
One small thing a lot of newcomers to C# and .Net in general are not aware of, is that Strings are immutable. What does that mean? That means a string you created cannot be altered. Strings can only be created and destroyed
Continue reading Small Tip: C# Strings are immutable
In previous posts we discussed about casting using the ‘as’ operator instead of using the ‘classic way’ of casting (more info here). But there are a few things we need be careful when using ‘as’ and ‘is’ operators.
Continue reading Pattern Matching and casting using ‘is’ and ‘as’
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
We 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.
CustomObject a = new CustomObject();
object b = (object)a;
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
We all know what type casting is. It’s converting from one type to the other. But exactly is implicit type casting?
Well implicit type casting is a feature of C# that helps you convert instances of custom Classes you created from one to another.
Continue reading Custom Implicit and Explicit type conversions in C#
All languages, or at least most, have some way of passing a value by reference. When we wish to return more than one values from a method or simply if we want to use the classic value swap paradigm then we need to pass values by reference to our method. C has pointers (which in fact you are still passing the pointer to your method by value, but in fact that pointer has a reference to the variable you want to change) Visual basic has the ByRef argument and many other languages have their own way of doing this.
Continue reading Out vs Ref in C#
For some time now developers wanted to catch multiple exceptions in a single Catch statement in order to not repeat their code in multiple catch statements. This was not available in previous releases of C# and developers used different workarounds to achieve it.
Continue reading Capturing Multiple Exceptions in a single Catch statement in C# 6