I want to use the keyword init

Error CS0518 in the following code:

public record Point(int X, int Y);

public class classA
{
    public int id { get; init; }
}

As it was already mentioned, the init keyword is a “new” feature of C# 9+, so it’s not (yet) available in Unity.

The init keyword for properties is pretty similar to a “private set” accessor with the difference that a private setter can not be used in an object initializer. So you would need an explicit contructor and pass the wanted value through a contructor argument in order to set the property. That way the property is still read-only from outside the class.

public class classA
{
    public int id { get; private set; }
    public classA(int aID)
    {
        id = aID;
    }
}

Unity doesn’t seem to provide an init keyword

public record Point{ public int X; public int Y; }

public class classA{
    public int id {get; set;}
}

This code seems to be the best