Archiv der Kategorie: C#

C# Protected Internal vs Private Protected

C# offers the composed access modifiers “protected internal”. With C# 7.2 a new composed access modifier was added: “private protected”. Unfortunately, these modifiers are hard to understand as their names don’t reflect their meaning. Within this article I want to … Weiterlesen

Veröffentlicht unter .NET, C# | Kommentar hinterlassen

Ref Return and Ref Locals in C# 7

The C# language supports passing arguments by value or by reference since the first language version. But returning a value was possible by value only. This has been changed in C# 7 by introducing two new features: ref returns and … Weiterlesen

Veröffentlicht unter .NET, C# | Kommentar hinterlassen

Pattern Matching in C# 7

Patterns are used to test whether a value matches a specific expectation and if it matches patterns allow to extract information from the value. You already create such pattern matchings by writing if and switch statements. With these statements you … Weiterlesen

Veröffentlicht unter .NET, C# | Kommentar hinterlassen

Expression Bodied Members in C# 7

The concept of Expression Bodied Members (EBM) was introduced with C# 6 and as it becomes popular, many enhancements were added with C# 7. Within this article I want to give you the full picture of this feature so I … Weiterlesen

Veröffentlicht unter .NET, C# | Kommentar hinterlassen

C# Array indexer vs. List indexer

The C# CLR contains a lot of nice collection classes. They are optimized for their individual use case. But from a common perspective they all have the same behavior we expect from a collection. But there is one exception from … Weiterlesen

Veröffentlicht unter .NET, C# | 1 Kommentar

Discard of return values and out parameters in C# 7

C# 7 allows to discard return values and out parameters. The underscore character is used as wildcard for these not required values. The following source code shows an example of a function call where the caller wants to ignore the … Weiterlesen

Veröffentlicht unter .NET, C# | Kommentar hinterlassen

Tuples in C# 7 (ValueTuple)

Within this article I want to give a short overview over the new Tuple features in C# 7. So far, we already had a Tuple class in C#.  But with the new one some technical details have changed and some … Weiterlesen

Veröffentlicht unter C# | Kommentar hinterlassen

Deconstruction in C# 7

C# 7 introduces a nice syntax to deconstruct a class and access all members. If you want to support deconstruction for an object you just must write a “Deconstruct” method which contains one or more out parameter which are used … Weiterlesen

Veröffentlicht unter C# | 1 Kommentar

Local or nested functions in C# 7

With C# 7.0 it is possible to create functions nested within other functions. This feature is called “local functions”. The following source code shows an according example.   The function “Calc” is nested within the function “DoSomething”. As a result, … Weiterlesen

Veröffentlicht unter C# | Kommentar hinterlassen

C# 7: binary literals, digit separators, out variables

Within this article I want to introduce some of the minor but helpful new features. These are binary literals, digit separators and out variables. Binary Literal So far, we could use decimal and hexadecimal literals in C#. With C# 7.0 … Weiterlesen

Veröffentlicht unter C# | Kommentar hinterlassen