.NET 6 Preview 7의 새로운 기능 [WIP]

벌써 Preview 7이군요. 올해도 빨리 갑니다;

4개의 좋아요

What’s new in .NET 6 Preview 7 [WIP] · Issue #6444 · dotnet/core (github.com)

암묵적 네임스페이스 import 기능은 TLP의 완성이죠. :+1:

For example, an empty web app looked like this:

using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
app.MapGet("/", () => "Hello World!");
app.Run();

but now it’s simplified to:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
app.MapGet("/", () => "Hello World!");
app.Run();
3개의 좋아요

호오 .NET 콘솔 템플릿이 최신 관용구가 앞으로 적용될 예정이군요. 막 C#을 접하는 친구들에게 쉬운 느낌을 줘서 접근성이 높이질것이라는데 좋은 변화라 생각합니다.

3개의 좋아요

최신 문법을 입힌 상태로 작성한 코드를 보고 C#이 아니라고 오해하실 분들도 꽤 있을것 같군요 :grin:

3개의 좋아요

Generic Math가 포함될 예정인가 봅니다.

public static TSelf Sum<TSelf>(IEnumerable<TSelf> values)
    where TSelf : INumber<TSelf>
{
    TSelf result = TSelf.Zero;

    foreach (var value in values)
    {
        result += value;
    }

    return result;
}

이 기능은 C# 10에 포함될 Static abstract members in interfaces의 기능을 이용한 것으로, 연산자 등 static의 인터페이스를 노출할 수 있게 해 특히 숫자 유형에 대한 일반 알고리즘을 제네릭으로 작성할 수 있게 합니다.

// Interface specifies static properties and operators
interface IAddable<T> where T : IAddable<T>
{
    static abstract T Zero { get; }
    static abstract T operator +(T t1, T t2);
}

// Classes and structs (including built-ins) can implement interface
struct Int32 : …, IAddable<Int32>
{
    static Int32 I.operator +(Int32 x, Int32 y) => x + y; // Explicit
    public static int Zero => 0;                          // Implicit
}

// Generic algorithms can use static members on T
public static T AddAll<T>(T[] ts) where T : IAddable<T>
{
    T result = T.Zero;                   // Call static operator
    foreach (T t in ts) { result += t; } // Use `+`
    return result;
}

// Generic method can be applied to built-in and user-defined types
int sixtyThree = AddAll(new [] { 1, 2, 4, 8, 16, 32 });
4개의 좋아요

이 기능이 매우 기대됩니다!!/////

2개의 좋아요

아직은 proposal 단계이고, 작업을 시작하진 않았네요. 닷넷 6에 들어가기에는 변화 폭이 큰 기능이라 아직은 알 수 없는 부분인 것 같아요! 참고하시면 좋을듯 합니다.

3개의 좋아요