Microsoft: Here’s programming language C# 9 preview for .NET plus full Blazor WebAssembly

Among the .NET news out of Microsoft Build 2020 is a new preview of C#, Microsoft’s programming language from the .NET team, plus a fully supported release of Blazor WebAssembly.

According to Microsoft’s lead C# maintainer Mads Torgersen, C# 9.0 strives for “greater clarity and simplicity in common coding scenarios”. But with this release the language is especially focused on “supporting terse and immutable representation of data shapes”.

C# was released in the early 2000s and was created by Microsoft technical fellow Anders Hejlsberg, who also created Microsoft’s popular extension of JavaScript for big applications, TypeScript.

The C# 9 preview comes about a year after C# 8’s release, which came alongside Visual Studio 2019 just ahead of Build 2019. C# 8 and F# 4.7 shipped with .NET Core 3.0.

The work on supporting terse and immutable representation of data shapes focuses on object initializers, which let users assign values to properties of an object at creation time. But as Torgersen explains, a big limitation today is that properties must be mutable for object initializers to work.

“They function by first calling the object’s constructor (the default, parameterless one in this case) and then assigning to the property setters,” he explains.

“Init-only properties fix that! They introduce an init accessor that is a variant of the set accessor which can only be called during object initialization,” he added, providing the example below to demonstrate.

public class Person

{

public string FirstName { get; init; }

public string LastName { get; init; }

}

Torgersen also suggests init-only properties are also useful to make individual properties immutable. He details more improvements for supporting immutable data such as with-expressions coming to C# 9.0 in a blogpost.

In related .NET and C# news, Microsoft has officially released Blazor WebAssembly, which until now was in preview. Blazor WebAssembly allows C# and .NET developers to build apps that run in the browser with WebAssembly but work like a normal desktop app – aka Progressive Web Apps (PWAs).

Blazor WebAssembly is one of four flavors of Microsoft’s Blazor project, which includes the supported Blazor Server render for web apps, a preview Electron renderer, and the recently released experimental Mobile Blazor Bindings for building native iOS and Android app using C# and .NET instead of JavaScript. Until now only Blazor Server was fully supported.

Daniel Roth, a principal program manager with Microsoft’s ASP.NET team, said Blazor WebAssembly is a “fully featured and supported release … that is ready for production use”.

To get started building PWAs with Blazor WebAssembly, users need to install the latest .NET Core SDK, version 3.1.300 or later. Users also need Visual Studio 2019 16.6 for Windows, Visual Studio for Mac 8.6, or VS Code with the C# extension.

Blazor WebAssembly allows apps to be hosted client-side in the browser using a WebAssembly-based .NET runtime.

“Blazor WebAssembly includes a proper .NET runtime implemented in WebAssembly, a standardized bytecode for the web. This .NET runtime is downloaded with your Blazor WebAssembly app and enables running normal .NET code directly in the browser. No plugins or code transpilation are required,” said Roth.

He added that Blazor WebAssembly works with all modern web browsers, both desktop and mobile.

“Similar to JavaScript, Blazor WebAssembly apps run securely on the user’s device from within the browser’s security sandbox,” he said.

“These apps can be deployed as completely standalone static sites without any .NET server component at all, or they can be paired with ASP.NET Core to enable full stack web development with .NET, where code can be effortlessly shared with the client and server.”

Roth notes that Blazor WebAssembly 3.2.0 is a fully supported release under the .NET Core Support Policy. As a first release. it is a Current release and not a Long Term Support (LTS) release. It also doesn’t inherit the LTS status of .NET Core 3.1.

“This means that once Blazor WebAssembly ships with .NET 5 later this year, you will need to upgrade to .NET 5 to stay in support. We expect Blazor in .NET 5 to be a highly compatible release,” noted Roth.

Read More

- No Comments on this Post -

Leave a Reply

Your email address will not be published. Required fields are marked *