Follow us

Visual Studio 2022 & .Net 6.0 Features

This article will explain some of great Visual Studio 2022 and .Net 6.0 including C# 10 features which definitely will love by all the developers.

As we know, now visual studio 2022 is out for public use, we can download: https://visualstudio.microsoft.com/downloads/

After download, it will provide you .Net 6.0 and C# 10 features support and you can select that framework/version while you creating new app.

File 
Error List 
Edit 
View D 
Additional information 
Console App 
Framework 
Linux 
ma c OS 
Windows 
Console 
.NET 6.0 (Long-term support) 
Entire Solution 
Description 
Error List 
Back 
Create

If you just want to use .Net 6.0, not visual studio 2022 then you can download .Net 6.0 runtime or SDK: https://dotnet.microsoft.com/download/dotnet/6.0

 

Visual Studio 2022 Important Features:

  • It is not 64 bit SDK and because of that overall load of any big to big solution, will load very frequently and you should be able to work with your bit project without any delay and easily debug and navigate to various part of your project.
  • It improved, search performance throughout the solution/project to find verry quickly as per your search text.
  • It build only the modified app not all of them exists inside solution. So think of you have solution with 100 projects and you just made some change into 2 projects and you are building your solution, so in that case it will only build those 2 modified projects.
  • As we know, we use visual studio for doing process dump analysis to find the CPU or memory utilization cause and with visual studio 2022, it will do that analysis very fast and also has little bit improvement in finding/navigating to actual problem code base from the analysis result panel.
  • Hot reload, where you can make change to your code while your app is in debug mode. So earlier, if our app is in debug mode and we want to make some change then we had to stop the debugging and then make the change and then run(F5) app again to see the change. But with Hot reload feature, it will save our much more time and see the change immediately.
    • Demo: When you app is in debug mode, just do change and then click on Hot Reload button to see the latest change.

e • Continue 
Lifecycle Events • Thread: 
Process: [184C40] ConsoleApp.exe 
Program.cs -a X 
ConsoleApp 
// See https: //aka ate for more information 
Console. World! 
Li 
bool run = true; 
int executionCount 
8whiIe (run) 
e; 
6 
12 
continue this ro ram?" 
Stack Frame 
again . 
- 
Console . WriteLine "Do ou want to 
onso e . rl e Ine execu Ion oun 
o you 
run . ToStringC) . ToLowerC) 
if (run) 
executionCount++; 
Console. program execution 
nan 
o con Inue IS program 
" "yes" ? true : false; 
o you wan o con 1 nue 
count is: 
{executionCount} " 
Hello World ! 
Do ou want to continue this 
Your ro ram execution count 
Do ou want to continue this 
ro 
Is: 
ro 
IS program. 
ram? 
ram a ain?

With above example, if you see when I ran this program, I had first message which is commented in screenshot and same displayed on output window and then on next execution when it hit to debug again, I commented the first message and made new message and then save and click on "Hot Reload icon" and debug to next step, it will new output.

Notes:

  • For using Hot Reload, make sure your code is in debug mode, so like before making change, your debug point is there inside your code base and then do change of code, save and then click on hot reload and then use F10 or F5 to debug next line/step to see the new change.
  •  Intellicode - improvement, suggest entire line while writing code based in your existing program code base and then just press tab and it will give you that line and you do not need to write that manually:

Program.cs• -E X 
ConsoleApp 
// See https: //aka ate for more information 
Console. World! 
bool run = true; 
int executionCount 
—while (run) 
e; 
6 
10 
- 
Console you want to continue this program?" ) ; 
run bool. Parse ) ; 
if (run) 
executionCount++; 
onsole. WriteLine

  • Code refactoring suggestions: If you keep cursor on any line, it will provide you suggestions to refactor your code at as per intelligence:

ConsoleApp. csproj 
ConsoleApp 
GlobalUsing.cs 
User.cs 
Prog ram.cs 
"Rajeev" 
x 
//using ConsoleApp. Models; 
Console. WriteLine( "Hello , 
new User 
user 
World ! ; 
1, Name 
Solution Explorer 
Search Solution Explorer (Ctrl+,•) 
Solution 'ConsoleApp.Net6Test' (I of I project) 
Dependencies 
Models 
co User.cs 
Ctt GlobalUsing.cs 
bool run = true; 
• int 
Inline temporary variable 
Move declaration near reference 
Use implicit type 
Convert to binary 
Convert to hex 
executionCoun 
Console. Write 
e; 
Lines 7 to 11 
bool run = true; 
executionCo 
while (run) 
•nt executionCount = 9; 
//ConsoIe .WriteLineC"Do you want to continue this program? n); 
A Warning: Declaration changes scope and may change meaning. 
Preview changes

  • GitHub action, to apply CICD pipeline while publishing code from visual studio to Azure, so while you right click on your app from solution explorer and publish and then choose azure service and you would have option to use Github action CICD and it will automatically setup for your which you can verify by going into Github after setup:

 

 

C# 10 important features:

  • Single line namespace declaring: To improve line of code we do not require braces { } for namespace body. We can simply add namespace top of the file and it will apply to that file:

User.cs 
ConsoleApp 
Program.cs 
ConsoleApp.ModeIs. • *Name 
namespace ConsoleApp. Models; 
O referencæ 
8pubIic class User 
public int Id 
public string 
{ get; 
Name { 
set; 
get; 
set; 
Solution Explorer 
Search Solution Explorer (Ctrl+,•) 
Solution 'ConsoleApp.Net6Test' (I of I project) 
ConsoleApp 
Dependencies 
Models 
Ctt User.cs 
co Program.cs

  • Global using: Now we can define our using list(namespaces) at one place and same will be used across all the files, so we do not need to write using statement with each files:

Demo: If I want to use above User class inside program.cs file, then I have import User namespace and similarly if User class will be used inside multiples files/classes then I will have to import with all such files/classes, so instead of doing that, I can create separate class let say(GlobalUsing.cs) and there I can import all such namespace as global which will automatically apply to all the files/class inside that project:

User.cs 
GlobalUsing.cs -E X 
ConsoleApp 
Program.cs 
CcnscIeApp.csprcj 
global using ConsoleApp.!T 
Solution Explorer 
Search Solution Explorer (Ctrl+,•) 
Solution 'ConsoleApp.Net6Test' (I of I project) 
88 Dependencies 
Models 
co User.cs 
cz GlobalUsing.cs 
co Program.cs

 

GlobalUsing.cs 
ConsoleApp 
User.cs 
Program.cs -a 
x 
Ccnsclezpp.csprcj 
//using ConsoleApp.Models; 
Console. WriteLi 
user 
User 
110, 
Id 
World ! ; 
1, Name 
"Rajeev" 
Solution Explorer 
Search Solution Explorer (Ctrl+,•) 
Solution 'ConsoleApp.Net6Test' (I of I project) 
88 Dependencies 
Models 
co User.cs 
Ctt GlobalUsing.cs 
cz Program.cs

 

One other thing, if you see with above example, we are using "Console.WriteLine()" but we have not import "using system" namespace anywhere and this is because "ImplicitUsings" setting is enabled on app level by default:

GlobalUsing.cs 
ConsoleApp.csproj -E X 
User.cs 
Program.cs 
8<Project NET. 
8 <PropertyGroup> 
<OutputType>Exe</OutputType> 
<TargetFramework>net6. ee/TargetFranework> 
< / PropertyGroup> 
Solution Explorer 
Search Solution Explorer (Ctrl+,•) 
Solution 'ConsoleApp.Net6Test' (I of I project) 
Dependencies 
Models 
Ctt User.cs 
Ctt GlobalUsing.cs

  • Record type with class and struct: Struct properties are mutable by default, while record class properties are immutable. However, you can declare a readonly record struct, which is immutable and matches the record class type:

So, with above example, if you see when I am trying to update record class name value then it is throwing compilation error.

Below screenshot, how I am calling this class and method from program.cs:

 

More to come soon....

Categories/Tags: Visual Studio 2022~VS 2022~.Net 6~C# 10

Recent Articles

1

AWS Saving Plan - Cost optimization tips

2
3

AWS RDS Key Concepts & Why you should use it?

4
5

Open-Search/Kibana - Multi Tenancy Setup

See All Articles