C# 9 - Top-Level Statements
Claudio Bernasconi
0:00 / 0:00
C# 9 - Top-Level Statements
8 536 просмотров · 5 лет назад
Claudio Bernasconi
19,8 тыс. подписчиков
8 536 просмотров · 5 лет назад
C# requires a lot of boilerplate code even for simple console applications. We need a namespace, a Program class, and even a static Main method.
How brilliant would it be if we could create a new file and start writing our code?
C# 9 introduces top-level statements. Top-level statements allow us to write C# statements without explicitly creating a namespace, a class, and a static Main method as an entry point to our program.
Top-level statements make C# feel simpler, and they help create short example programs to demonstrate language features. Also, it should be more comfortable for beginners to learn all the language features one-by-one.
Top-level statements are essentially a compiler feature. That means that even if we don't write the boilerplate code ourselves, the compiler does the work for us, and we end up with the same old structure.
The only limitation I experienced while working with top-level statements is that you can only have top-level statements in a single file.
Top-level statements are a compiler feature introduced in C# 9. Top-level statements allow us to write short and concise C# programs. We can either use them to demonstrate specific language features or make it simpler to get started with C#.
00:00 Introduction
00:38 Top-Level Statements
02:40 Generated IL Code
03:15 Using command-line arguments
03:52 Working with Types
04:32 Limitations
04:55 Conclusion
🔥 C#/.NET Bootcamp: The Fundamentals & more (Code FRIENDS10 for 10% OFF)*
https://claudiobernasconi.ch/dotnet-c...
📌 .NET Developer Roadmap
https://claudiobernasconi.ch/learn-do...
📌 YouTube Playlists:
The FREE Blazor Crash Course: • The FREE Blazor Crash Course (.NET 5) | Ge...
C# Programming: • How to Create Modern C# Console Applications
📌 Install and Use C# 9 in Visual Studio 2019:
• Install and Use C# 9 in Visual Studio 2019...
📌 SharpLab:
https://sharplab.io/
✅ SUBSCRIBE FOR MORE VIDEOS
Subscribe: 🔔 https://claudiobernasconi.ch/Subscribe
🚀 CONNECT & SUPPORT
Twitter: / chbernasconic
Blog: https://claudiobernasconi.ch
Newsletter: https://claudiobernasconi.ch/newsletter
CREDITS
🎵 https://www.bensound.com/
🎵 https://www.streambeats.com/
Affiliate Link: I earn a small commission at no additional cost