Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Tuesday, March 10, 2020

Enabling C# 7.1 in Visual Studio 2017 projects

Today, when I tried to compile one of the Visual Studio projects in our solution - I received the exception "Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater". (For more info see default literal in C# 7.0)



To enable C# 7.1 you need to following these steps:

  • Right click on your project and select Properties, next navigate to the build tab and click Advanced

  • Next you can either choose C#7.1 from the list or choose C# latest minor version (latest).

Thursday, August 01, 2019

Code tip: Nullable datetime in C#

Nullable types are used when you need to represent the value of an underlying type. By default DateTime is not nullable in C# because it is a Value type, but using the Nullable construct (or the ? shorthand), you can assign the null literal to the DateTime type. Syntax is below:

 DateTime? dt = null;  
 Nullable<DateTime> dt = null;