ufcpp-live / UfcppLiveAgenda

@ufcpp live streaming agenda
MIT License
24 stars 2 forks source link

C# 11.0 / .NET 7.0 / Visual Studio 2022 17.4 正式リリース記念 #63

Closed ufcpp closed 1 year ago

ufcpp commented 1 year ago

記念(新しいネタがあるわけではない)。

公式アナウンス類:

去年同様、

C# 11 の機能一覧を載せて、「何か質問ある?」「雑談しようよ」

な配信になる予定。

参考: C# 11.0 の新機能 (うちのサイト) 目次:

ufcpp commented 1 year ago

GlobalPackageReference?

ufcpp-live commented 1 year ago

net6.0 から 7.0 への書き換えで何かエラー出た?

class FakeType : Type で、

typeof(DateTime).GetCustomAttribute<ObsoleteAttribute>();
// ↑こいつが、中で、 (ObsoleteAttribute[])GetCustomAttribute() してる
// ↓みたいな実装してると…

#if false
    public override object[] GetCustomAttributes(bool inherit)
    {
        return Array.Empty<object>();
    }

    public override object[] GetCustomAttributes(Type attributeType, bool inherit)
    {
        return Array.Empty<object>();
        // Array.CreateInstance(attributeType, 0) に書き換え必要だった
    }
#endif
ufcpp-live commented 1 year ago

ASP.NET の方で NRT 警告はいくつか増えた。

ufcpp-live commented 1 year ago

XUnit の Assert.NotNull にちゃんとアノテーションが最近入ったらしい。

Xunit.Assert.NotNull(x);
if (x == null) return; // NotNull に DoesNotReturn とかついてない…
ufcpp-live commented 1 year ago

image

var raw = """
                 abc
                 """;
ufcpp-live commented 1 year ago

image

var abcde = 1;
var أبجدية123 = 2; //arabic
var עברית123 = 3; // hebrew
ufcpp-live commented 1 year ago
var Vectorס3 = 1; 
var ס3Vector = 2;

Console.WriteLine(Vectorס3);
Console.WriteLine(ס3Vector);
ufcpp-live commented 1 year ago

相変わらず OutputEncoding 指定必須

image

ufcpp-live commented 1 year ago

image

ufcpp-live commented 1 year ago
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

unsafe
{
    var x = new int[3, 5];
    var adr1 = Unsafe.As<int[,], nint>(ref x);
    var adr2 = (nint)Unsafe.AsPointer(ref x[0, 0]);
    Console.WriteLine(adr2 - adr1); // 32
}

unsafe
{
    var x = new int[3, 5, 7];
    var adr1 = Unsafe.As<int[,,], nint>(ref x);
    var adr2 = (nint)Unsafe.AsPointer(ref x[0, 0, 0]);
    Console.WriteLine(adr2 - adr1); //40
}
ufcpp-live commented 1 year ago

image

ufcpp-live commented 1 year ago

image

ufcpp-live commented 1 year ago
var array = new[] { 1, 2, 3 };

for (int i = 0; i < array.Length; i++)
{
    // ここの range check は JIT 時に最適化で消える
    // (これは元から)
    var x = array[i];
}

var a2 = new[,] { { 1, 2 }, { 3, 4 } };

for (int i = 0; i < a2.GetLength(0); i++)
    for (int j = 0; j < a2.GetLength(1); j++)
    {
        // .NET 7 で、これの range check も消えてくれるとかだっけ?
        // GetLength() が intrinsic になったという話?たぶん。
        var x = a2[i, j];
    }
ufcpp-live commented 1 year ago

3年後が楽しみだなー

net10