Take advantage of the new top-level statements in C# 9.0 to eliminate boilerplate code and make your programs more readable, maintainable, and efficient.
When writing programs in the C## programming language, you invariably need to write a lot of boilerplate code — even for simple console applications. Imagine that you want to write some code to test whether a library or an API is functioning properly. You might write a console application to accomplish this, but you’re nonetheless constrained to follow standard C## semantics. You must write your code inside the Main method.
Top-level programs, a new concept introduced in C## 9.0, allow you to write code for simple programs sans the need to write boilerplate code. Top-level programs are a great new feature that allows you to write cleaner, shorter, and simpler code. You can take advantage of top-level programs to explore new ideas. This article discusses how you can work with top-level programs in C## 9.0.
To work with the code examples provided in this article, you should have Visual Studio 2019 installed in your system. If you don’t already have a copy, you can download Visual Studio 2019 here. Note that C## 9.0 is available in Visual Studio 2019 version 16.9 Preview 1 or later, and in the .NET 5.0 SDK.C# 9
How to use C#9 and C#8 features in JustMock unit tests
C# 9 introduces a super fun feature: Top-level programs. What’s a Top-level program ? This is a simpler way to write your program on its top level: a simpler Program.cs file Before C# 9 and with C# 9 In your main program you have been able to write whatever you want, for example: async calls (obviously) accessing args (obviously) local functions (obviously again !)
C# 9.0 introduces many new language features, and with this blog post I start a little series to look at some of those new features. Let’s start in this post with top-level statements. When you create a new Console application with C#, you get a lot of boilerplate code. Below you see the code of a new app with the name ThomasClaudiusHuber.ConsoleApp.
C/C++ problems. If you are familiar with C/C++then you must have come across some unusual things and if you haven’t, then you are about to. The below codes are checked twice before adding, so feel free to share this article with your friends.
After launching .NET 5 and C# 9, I was utterly obsessed with the Top Level Program (a.k.a. TLP) feature. TLP delivers quick and fast prototyping for the .NET application and makes the most immediate entries for my work.