First Look At A .NET 6 Feature In Visual Studio 2022

Introduction

In today’s article, we will take a first look at the latest version of Visual Studio. This is Visual Studio 2022. This product has not yet been released in the production version. However, the preview version is available for testing and research purposes. We will also look at a new feature in the .NET 6 framework which is available along with Visual Studio 2022. So, let us begin.

Downloading and Installing Visual Studio 2022 – Preview version

The preview version of Microsoft Visual Studio 2022 is available here.

This is the first Visual Studio version to be 64-bit which ensures larger solutions would not lead to memory issues. Also, it can be installed alongside older versions of Visual Studio.

Creating our first application in Visual Studio 2022

After you install the Visual Studio 2022 application, run it and you will see the below,

.NET 6 Feature In Visual Studio

.NET 6 Feature In Visual Studio

.NET 6 Feature In Visual Studio

.NET 6 Feature In Visual Studio

As you see above, the .NET 6.0 version is also in preview and hence we can expect some features to change in the final version.

If we look at the project just created, we see the below,

.NET 6 Feature In Visual Studio

We can also look at the Visual Studio version from the Help-> About Microsoft Visual Studio.

.NET 6 Feature In Visual Studio

As you can see from the above, I am using Microsoft Visual Studio Community 2022 Preview version which is 64-bit.

Now, let us add some code and look at a new feature introduced with .NET 6. Update the “Program.cs” file with the below code,

using System;

var currentDateTime = DateTime.Now;
Console.WriteLine(currentDateTime.ToString());

var currentDateOnly = new DateOnly(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day);
Console.WriteLine(currentDateOnly.ToString());

var currentTimeOnly = new TimeOnly(currentDateTime.Hour, currentDateTime.Minute, currentDateTime.Second);
Console.WriteLine(currentTimeOnly.ToString());

You will notice that as you type, Intelli-sense in Visual Studio 2022 gives you options on what you probably want to do and allows you to accept these options, if desired.

.NET 6 Feature In Visual Studio

Now, we run the application and see the below,

.NET 6 Feature In Visual Studio

The two new features used here are simple ones. In earlier versions, we had a Date-Time type. In .NET 6 we now have the option or type to store either just a date or just a time.

Summary

In this article, we took a look at the latest Visual Studio version 2022 and a feature of .NET 6 which comes integrated in Visual Studio 2022. In future articles, I will look into other features of .NET 6 and Visual Studio 2022. Happy coding!


Recommended Free Ebook
Similar Articles