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. 

RECENT NEWS

Reassessing AI Investments: What The Correction In US Megacap Tech Stocks Signals

The recent correction in US megacap tech stocks, including giants like Nvidia, Tesla, Meta, and Alphabet, has sent rippl... Read more

AI Hype Meets Reality: Assessing The Impact Of Stock Declines On Future Tech Investments

Recent declines in the stock prices of major tech companies such as Nvidia, Tesla, Meta, and Alphabet have highlighted a... Read more

Technology Sector Fuels U.S. Economic Growth In Q2

The technology sector played a pivotal role in accelerating America's economic growth in the second quarter of 2024.The ... Read more

Tech Start-Ups Advised To Guard Against Foreign Investment Risks

The US National Counterintelligence and Security Center (NCSC) has advised American tech start-ups to be wary of foreign... Read more

Global IT Outage Threatens To Cost Insurers Billions

Largest disruption since 2017’s NotPetya malware attack highlights vulnerabilities.A recent global IT outage has cause... Read more

Global IT Outage Disrupts Airlines, Financial Services, And Media Groups

On Friday morning, a major IT outage caused widespread disruption across various sectors, including airlines, financial ... Read more