以下の内容はhttps://www.hanachiru-blog.com/entry/2023/04/24/120000より取得しました。


【Unity】Unityでinitアクセサーを利用できるようにする(Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported)

はじめに

C#9.0よりinitアクセサーが登場しました。

public int Year { get; init; }

しかし現状のUnity(Unity2023.1で実験)で利用しようとすると以下のようなエラーが出てきてしまうようです。

error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported

これの対処法について紹介したいと思います。

解決方法

namespace System.Runtime.CompilerServices
{
    internal static class IsExternalInit { }
}

以下のコードをプロジェクト内に書くとエラーが出てこなくなります。




以上の内容はhttps://www.hanachiru-blog.com/entry/2023/04/24/120000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14