BT

Facilitating the spread of knowledge and innovation in professional software development

Contribute

Topics

Choose your language

InfoQ Homepage Articles C# 9 and .NET 5: Book Review and Q&A

C# 9 and .NET 5: Book Review and Q&A

This item in japanese

Bookmarks

Key Takeaways

  • The book C# 9 and .NET 5, by Mark Price, is an implementation-oriented guide on developing .NET cross-platform applications. The author covers the main types of applications that can be built with C# 9 and .NET 5, providing a very comprehensive development guide to .NET beginner to intermediate programmers .
  • The author talks about the new features of C# 9 and the context in which .NET 5 is inserted. He also talks about the importance of knowing the .NET internals for developers that need to work with legacy .NET applications.
  • The book includes chapters on frameworks related to .NET 5, such as Entity Framework Core and ML.NET. These chapters were included according to what the author thinks as essential capabilities necessary for a developer nowadays - which includes Machine Learning.
  • The author emphasizes that Blazor Server and Blazor WebAssembly both use the same component model. This means that if a programmer is careful about how they design their Blazor components, they can be shared between either hosting model. The book has a dedicated chapter discussing the available Blazor hosting models.
  • .NET 6, the next Long Term Support release for .NET, will be available in November 2021. Any existing .NET Framework projects should start being migrated today to .NET 5. Considering the necessary refactoring and adjustment time, this will allow companies to take advantage of the full three years of .NET 6 support from Microsoft.

The book C# 9 and .NET 5, by Mark Price, is a practical guide on developing .NET cross-platform applications. The book is concise, implementation-oriented, and each subject is presented with a hands-on walkthrough. The author covers the main types of applications that can be built with C# 9 and .NET 5, providing a very comprehensive development guide to .NET programmers.

InfoQ reviewed the book and interviewed Mark Price on the goals and contents of C# 9 and .NET 5.

InfoQ: Why did you write this book?

Mark: I wrote this book because I felt that I could add something that was missing from the existing marketplace of C# books. When Packt approached me in the summer of 2015 to write a C# book, I was already familiar with many of the current C# books because I had bought them over the years for myself. At the time, even Microsoft wasn’t sure what their long term plans were for .NET which is why they named the new slimmed-down version, “.NET Core”. They didn’t know at the time that it would grow in popularity and eventually be the generational shift that .NET needed to become modern and cross-platform. 

InfoQ: What is your target audience?

Mark: The target audience for my book is beginner to intermediate programmers. By that I mean two primary audiences. 

First, someone new to C# and .NET. They will have the best experience if they already have familiarity with another language or at least have some Science, Technology, Engineering, and Mathematics (STEM) background. But anyone who is curious and eager to learn should be able to follow the book and gain skills and knowledge.

Second, someone who has worked with C# and .NET in the past, but has perhaps got rusty skills or is stuck on the .NET Framework and wants to make the jump to modern cross-platform .NET. 

InfoQ: How do you think .NET 5 changes the previous .NET ecosystem? If someone decided to start following the software development career today, would they have more reasons to choose the .NET path now?

Mark: .NET Core 3.1 was the first modern version of .NET that I confidently recommended that all programmers embrace because that version clearly surpassed .NET Framework 4.8. So it was the first step on a journey to replace .NET Framework. It is a Long Term Support release so Microsoft will support it until December 2022. .NET 5 improves performance in many areas and adds new platforms like Blazor WebAssembly but it will be .NET 6 that completes the journey to a single .NET for all platforms including mobile. 

InfoQ: Chapter 2 briefly explains the evolution of C#. Which do you think are the best features of C# 9?

Mark: The feature with the best potential is Records. I have a feeling that some programmers will use Records without actually needing to, just because they have heard that Records are the cool new feature. Records enable a functional programming style by providing immutable objects. I plan to explore the functional programming style in more depth and add some code examples in the next edition that show more of the “why” to use Records as well as the “how” to use Records that I included in the fifth edition. 

Other new C# 9 features like top-level programs might be useful in some specialized scenarios or for learning. I think my favorite new language feature and the one I will use frequently is target-typed new object instantiation because it simplifies code that programmers write many times every day.

InfoQ: Your book covers not only C# 9 but also several aspects of .NET 5 - including packaging and standards. Why is it essential for someone that just started learning C# 9 to understand .NET Standard?

Mark: .NET programmers do not have the luxury of only working on greenfield applications i.e. completely new applications that can use .NET 5 for all components. .NET programmers must be ready to work on projects that use older versions. There are many more projects written for .NET Framework that need maintaining than fresh new projects using .NET 5. Understanding how to create new class libraries that can work with older platforms is very important. .NET Standard 2.0 enables code to work between old and new versions of .NET, as well as between Windows-only .NET Framework, mobile apps using Xamarin, and modern cross-platform .NET Core 2.0 and later. 

InfoQ: In Chapter 11, you explain how to work with databases using Entity Framework Core. In your opinion, what are the advantages of using it instead of an object-relational mapper such as NHibernate (or any other similar)?

Mark: The big one is, of course, support from Microsoft. Entity Framework Core (EF Core) is Microsoft’s official Object-Relational Mapper (ORM). As the default ORM, it is used in more projects and therefore gets more real world testing and any issues are fixed faster. More programmers are familiar with it so they are easier to recruit onto projects. As with most technology, the benefits are less about the features of the technology, and more about human factors. 

InfoQ: There's been a lot of excitement around Blazor - especially after the release of Blazor WebAssembly 3.2 earlier this year. In your book, you talk about Blazor a lot, both server and client-side. Could you explain the difference between them and when a programmer should choose to use one or the other?

Mark: The first thing to emphasize is that Blazor Server and Blazor WebAssembly both use the same component model. This means that if a programmer is careful about how they design their Blazor components, they can be shared between either hosting model, as I show in the chapter about Blazor in my book. Now let’s talk about the two hosting models. 

For a programmer already familiar with ASP.NET Core, Blazor Server is easier to work with because the code runs on the server where all the data resources are and so the programmer doesn’t have to handle as much complexity. But Blazor Server requires a permanent connection between each browser client and the server. This uses resources on the server and limits the maximum number of clients and therefore the scalability of your solution. 

Blazor WebAssembly is harder to work with because the code runs in the browser and is limited to resources within the browser. Any data needed, for example to update the user interface, must be fetched from the server. This typically requires authentication and deserialization and so on. Due to the disconnected nature of the client and server, the solution can scale much better. And since the programmer will have to create a web service anyway, it also enables other types of client, for example, mobile, desktop, or smart speaker. 

InfoQ: .NET 5 brings a lot of improvements related to gRPC, which is effectively replacing Windows Communication Foundation (WCF) for developing service applications on .NET. Can you tell us how exactly gRPC is different from WCF and what it brings to the .NET ecosystem in terms of advantages over WCF?

Mark: Microsoft’s Windows Communication Foundation (WCF) is a simple yet powerful and extendable technology so I was sad to see it did not make the jump to modern .NET. It had the concept of endpoints defined by ABC: address, binding, and contract. Contracts were defined using C# interfaces and they specified the functionality and was therefore separated from the implementation. Set up was primarily done in a configuration file so changes could be made without recompiling your apps. It had strong support for multiple common communication technologies like MSMQ, SOAP, and REST. It was designed to handle future technologies so it is a shame that Microsoft didn’t implement WCF in modern .NET and then just add support for gRPC to it. As its name suggests, WCF is limited to Windows because it is only implemented in .NET Framework.

gRPC is a Google-defined technology and supports any programming language. It is more limited than WCF because it only supports Remote Procedure Call (RPC) style interactions. It uses Protocol Buffers (protobuf) binary format to send messages. My book does not include any code examples of gRPC but if there is enough interest then I might include some in the sixth edition. 

InfoQ: In Chapter 21, you talk about developing cross-platform mobile apps. How is the .NET 5 framework prepared to support this development?

Mark: .NET 5 does not support mobile apps. That will have to wait for .NET 6. Chapter 21 has to use Xamarin, the mobile version of .NET, instead.

InfoQ: Despite not being a part of .NET 5, in your book, you talk about ML.NET, a machine learning framework for the .NET ecosystem. Why did you choose to include this framework in your book? Isn't it a very specialized framework, or is it something accessible even to someone that just started learning .NET development?

Mark: Entity Framework Core is not part of .NET 5 either but I include a whole chapter on that because working with databases is an essential capability of any developer platform. Machine learning is rapidly becoming just as essential as working with databases. So since the fourth edition, I include a chapter showing how to use Microsoft’s ML.NET machine learning library. But, as I show in the book, adding intelligence to your apps is not easy. I suspect that lots of programmers buy books that are 100% about machine learning and give up after chapter 1. So I wrote the machine learning chapter in my book partly to save them from getting disappointed after buying a whole book as well as trying to show one complete practical example of adding intelligence to a commerce website by adding product recommendations. 

If a programmer has just started learning .NET development then the chapter on machine learning is arguably the most challenging. But including allows programmers to decide for themselves if machine learning is an area they want to dive into now, or wait until they are more experienced or the platforms are easier for non-specialists to use. 

InfoQ: What do you think we can expect for the .NET ecosystem in 2021?

Mark: Microsoft will release .NET 6.0 on Tuesday, November 9, 2021. As well as all project types supported by .NET 5, .NET 6 will support mobile app development using .NET MAUI (Multi-platform Application User Interface). .NET MAUI is effectively Xamarin.Forms 6 so mobile developers can start building projects today using Xamarin.Forms 5 and it should be a small amount of work to upgrade to .NET MAUI when it is released with .NET 6.

Microsoft will release .NET 6 Previews monthly throughout 2021, including Release Candidates in September and October with Go Live licenses. .NET MAUI will have less frequent previews and will be packaged separately like EF Core is today. 

EF Core 6 will include some useful new features. Microsoft has publicly asked for feedback to plan what those features are.

C# 10 will include some rarely used features and some refinements that enable more functional programming style.

.NET 6 will be a Long Term Support release. Enterprises will want to target it for important projects. It will be easy to upgrade most projects from .NET 5 to .NET 6 simply by changing the project file so programmers can start work on those projects today using .NET 5 and then “flip a switch” to target .NET 6 and then get three full years of support from Microsoft. Any existing .NET Framework projects should start being migrated today using .NET 5 for similar reasons. It might take a year to refactor and rewrite the parts that need to be changed. 

About the Author

Mark J. Price is a Microsoft Specialist: Programming in C# and architecting Microsoft Azure Solutions, with more than 20 years of educational and programming experience.

 

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.