-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LDM 話続き& .NET 6 Preview 2 #29
Comments
45:34~ #nullable enable
using System.Collections.Generic;
_ = new[] { 1 }.FirstOrNull();
_ = new[] { "" }.FirstOrNull();
static class EnumerableClass
{
public static T? FirstOrNull<T>(this IEnumerable<T> source) where T : class => null;
// ここにあるとダメ。 .NET の型システム的に where 違いのオーバーロード無理。
//public static T? FirstOrNull<T>(this IEnumerable<T> source) where T : struct => null;
}
static class EnumerableStruct
{
// 別の型にあるなら OK。
public static T? FirstOrNull<T>(this IEnumerable<T> source) where T : struct => null;
} |
1:00:32~ 引数なしコンストラクターがないことで ImmutableArray の類が困ってる // 書きたいコード
//struct FixedArray4
//{
// int[] _array = new int[4];
// public int this[int index] => _array[index];
//}
// しょうがないから書くコード
struct FixedArray4
{
int[] _array;
private FixedArray4(int[] array) => _array = array;
// これがいやーーーーー
public static FixedArray4 Create() => new(new int[4]);
public int this[int index] => _array[index];
} |
1:03:18~ using System;
using System.Collections.Immutable;
// 構造体の引数なしコンストラクターがないというか、
//ImmutableArray<int> array = default;
// 今、 new() が default 扱いされてしまい…
ImmutableArray<int> array = new();
// IndexOutOfRange ほしいのに、ぬるぽが来る
// 何を new したんでしょう…
Console.WriteLine(array[0]);
// この判定が必要
Console.WriteLine(array.IsDefault); |
1:08:35~ 引数なしコンストラクターは C# 6.0 のときに一度やろうとして、Activator.CreateInstance のバグを踏んだことで取りやめになった using System;
// C# 6.0 の頃、これが構造体コンストラクターを呼んでくれないというバグあった。
var point = Activator.CreateInstance<Point>();
struct Point
{
public int[] _data;
// .NET のメタデータ的には昔から許されてた。
// C# コンパイラーをちょこっといじれば可能だったらしい。
public Point() => _data = new int[1];
} |
1:14:59~ (今持っていない状態でリリース済みの)既存の構造体に引数なしコンストラクターを足すのは破壊的変更になります 引数なしコンストラクターを足した瞬間にコンパイルできなくなるコードの例: void m(Point p = new())
{
}
struct Point
{
// この行の有無だけで m がエラーになるかどうか変わる。
// つまり、引数なしコンストラクターの追加は破壊的変更。
public Point() { }
} |
using System;
void m(Point p = new()) // warning waves で警告くらいは出すべきかも
{
}
struct Point
{
} |
1:28:12~ 今現在、 今後、↑この前提は必ずしも正しくなくなる。 using System;
m2<Point>();
// 今、「struct の時点で new() を満たす」という判定を受けてる。
void m1<T>() where T : new()
{
// new T() は中で Activator.CreateInstance<T>() を呼んでる
Console.WriteLine(new T());
}
// 今、これ許される。
// さすがに変えれない。
void m2<T>() where T : struct => m1<T>();
struct Point
{
// これを足すと破壊。
// new T() のところで MissingMethodException が出る。
private Point() { }
} |
1:37:00~ .NET って「0バイト構造体」が実はなかったりする(現時点では) using System;
unsafe
{
Console.WriteLine(sizeof(Empty)); // これ1
}
struct Empty { } |
1:39:44 にしてやっとサムネ回収。 var var = new var();
class var { }
@record record = new record();
record record { } |
1:41:18~ Visual Studio 上だといいけども… Roslyn みたいにsemantics見まくってるものと同水準のシンタックスハイライト、普通は期待できない。 |
1:44:10~ semantics 見なくてもいい文法になればちょっと GitHub とかブログサービスとかに優しくなれる // これ、破壊的変更するかも。
// 今後、semantics 見なくても「var はここで出てきたらキーワード」扱いしたい
var var = new var();
// record はそうだから。
// そして C# 9.0 がリリースされて、それで困った人もいない。
record record = new record();
// @ を付ければいいじゃない。
//@record record = new record();
class var { }
record record { } |
2:16:55~ global using の扱いは「すべてのファイルの先頭にその using をべた展開するのと同じ扱い」になる 2:17:13~「通常 using よりも上」みたいな新しいスコープは導入しない global using System;
using System;
// これ OK
using D = System.DateTime;
// これダメ
// global using でもダメということにするらしい。
// global using はべたに「すべてのファイルの先頭にその using を展開」扱い。
using D1 = DateTime;
;
namespace A
{
// これは OK
using D = DateTime;
} |
2:06:18 sharplab 仕事はえぇ (global using の feature ブランチをもう試せる) |
using System;
var x = 1;
// エイプリルフールその1、オタマジャクシ演算子
Console.WriteLine(~-x);
Console.WriteLine(-~x); |
「 60進数リテラル」「エイプリルフール」 |
2:34~ 開幕「きのこ」「たけのこ」「どうでもいい」「そっとしておこう…」 |
28:30~ PriorityQueue |
41:55~ SignalR に nullable アノテーション付いたらしい → 制約なし |
45:34~ |
54:22~ NullableContext 属性の話 |
59:40~ 構造体の引数なしコンストラクター |
1:22:30~ C## 平均律だと D = C## だけど、純正率だと厳密には違う音なんだっけ? |
1:27:20~ C# 1.0 でジェネリクスなかったから3年くらいは悲しかった |
1:46:43~ class は(文脈抜きで)単純にキーワードなので C# だと 1:48:10 「cls とか略すと clear screen? ってなる」「C# script には 1:51:46~ 文字コードさえ覚えれいれば何の文字でも F5 キーで入力可能 |
2:24:57 「global using 使いたいと思わない」とかいうけど、ソースコード新規追加したときのデフォルトの 今(.NET 5 以降)は |
2:45:42 この週末は YouTube の調子ほんと悪かった |
2:48:40~ エイプリルフールネタはやらないというか、「真に受けられて困る嘘はつくな」話 |
配信枠: https://youtu.be/NqJkCm85CSM
.NET 6 Preview 2 になってる。
前回残ったやつ:
そこからブログ1記事増えたやつ:
#27 も未消化多い。
The text was updated successfully, but these errors were encountered: