1. Introduction
As a cross-platform, open source framework for building modern cloud-based, internet-connected applications, .NET Core has been a popular choice among developers. With the release of .NET Core 2.0 Preview2, Microsoft introduced many new features to improve the overall functionality and usability of the framework. In this article, we will take a detailed look at some of the most important features of .NET Core 2.0 Preview2.
2. .NET Standard 2.0
The .NET Standard is a formal specification of the APIs that are available in different .NET implementations. It provides a common set of APIs for all .NET implementations, which makes it easier to create libraries that can be used across different platforms. With .NET Core 2.0 Preview2, Microsoft has introduced .NET Standard 2.0, which includes many new APIs and enhancements. One of the most important enhancements in .NET Standard 2.0 is the support for the Span
2.1 Using Span
The Span
int[] numbers = { 1, 2, 3, 4, 5 };
Span span = new Span(numbers);
foreach (int n in span)
{
Console.WriteLine(n);
}
In the above example, we create a Span
3. C# 7.1
C# 7.1 is a minor update to the language that includes some new features and enhancements. .NET Core 2.0 Preview2 includes support for C# 7.1, which allows developers to take advantage of these new features.
3.1 Async Main
One of the most important new features in C# 7.1 is the ability to use async main methods. This allows developers to write asynchronous console applications without requiring a separate entry point. Here is an example of using async main:
class Program
{
static async Task Main(string[] args)
{
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("http://www.example.com");
return (int)response.StatusCode;
}
}
In the above example, we use the async keyword to mark the Main method as asynchronous, and then use the await keyword to call an asynchronous method. This allows us to write asynchronous code in a straightforward and natural way.
4. Conclusion
.NET Core 2.0 Preview2 introduces many new features and enhancements that can help developers build modern, cloud-based, internet-connected applications more easily and efficiently. With support for .NET Standard 2.0 and C# 7.1, developers have access to a wider range of APIs and language features, making it easier to write high-performance, modern applications that can run on a variety of platforms.