Am I Using C# 8.0?

Last week I was working on a C# project in VS2019 and I wanted to use some language features from C# 8.0 (in particular ‘using declarations’). So how do we check if a project is using C# 8.0? The logical place to look is the project settings. Right-click on the project and select Properties=>Build. Scroll … Read more

LINQ

LINQ (Language-integrated query) provides a common query syntax for dealing with objects, databases and XML. It was introduced in C# 3.0. In this post we shall look at using LINQ to Objects. LINQ to Objects can be used with enumerable objects such as arrays, lists and strings. There are two ways to access LINQ in … Read more

Categories C#

Generics

Generics in C# allow you to generalise classes and methods to work with different underlying types. Generics are used in many of the C# collections such as List, Vector and Queue. Using generics allows the compiler to enforce type-safety. List, Vector etc. are examples of generic classes. It is also possible to define generic methods. … Read more

Categories C#

Asynchronous Programming in C#

Tasks In .NET, the Task class enables us to run jobs asynchronously. It offers a more high-level framework than we saw in the previous post on threading, which means we don’t have to get involved with mutexes and signalling. There are two versions of the task class: the non-generic Task class which is for tasks … Read more

Categories C#

Threading in C#

Threads are an important concept in asynchronous programming. In this post we will cover creating threads and give a brief overview of some of the low-level synchronisation classes in .NET. Finally we look at the .NET thread pool which allows a series of tasks to be run in parallel. Creating threads The Thread class can … Read more

Categories C#

Lambda Expressions (C#)

Lambda expressions allow us to define anonymous expressions. You can use lambda expressions where where you might use a delegate function. Lambda expressions are defined using the lambda operator =>. There are two types of lambda expressions: An expression lambda which is defined by an expression. A statement lambda which is defined by a statement … Read more

Categories C#

Delegates and Events

A delegate is an object that holds a reference to a method. A delegate can be used to implement a callback mechanism, for example to receive notification of an event such as a user clicking on a button. Delegates are also useful when we consider of the principle of separation of concerns. For example, we … Read more

Categories C#

The Builder Pattern

In this post we will discuss the Builder Pattern. This is one of the standard creational design patterns. It is particularly relevant when dealing with complex objects which may be conceptually built up from a set of components. In this pattern, the object is often built up in stages rather than being created immediately in … Read more