Introduction to C# 6.0 syntax

Now let's add in the constructor as follows:

public SQLiteStorage(ISQLiteSetup sqliteSetup, ILogger log) 
    {
         _dbPath = sqliteSetup?.DatabasePath;
         _sqlitePlatform = sqliteSetup?.Platform;
         _log = log; _tag = $"{GetType()} ";
    }

Here we can see some C# 6.0 syntax. Using the question mark (?) after the constructor parameter sqliteSetup means that, if the object is not null, we can access the property. This avoids having to create an if statement such as the following:

If (sqliteSetup != null)
    _dbPath = sqliteSetup?.DatabasePath;

There is also some more C# 6.0 syntax with the following:

_tag = $"{GetType()} ";

The dollar sign ($) character is used for interpolated strings. Interpolated string expressions create a string by replacing ...

Get Xamarin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.