79219090

Date: 2024-11-24 00:18:32
Score: 2.5
Natty:
Report link

Not even close. I cannot even guess where did you get such ideas. What you are trying to do under init looks line constructor and belongs to a constructor.

As to real init it simply means “initialization-only”. This is the accessor used to make compilation fail if some code tries a write operation on a property except the constructor of the class having this property.

This is an example

class ReadWritePropertyDemo {
    internal ReadWriteDemo() {
        ReadableInternallyInitOnly = 42; // only here
        ReadablePubliclyAndWritablePrivately = 43; // and by other methods 
                                                   // of this class,
                                                   // see below
    }
    void SetterForOne(int value) {
        ReadablePubliclyAndWritablePrivately = value;
    }
    internal int ReadableAndWritableInternally { get; set; }
    public int ReadablePubliclyAndWritablePrivately { get; private set; }
    // write access only for derived classes in containing assembly:
    public int ReadablePubliclyLimitedWrite
        { get; private protected set; }
    public int ReadablePubliclyAndWritableByDerivedClasses
        { get; protected set; }
    internal int ReadableInternallyInitOnly { get; init; }
    // and a lot more combinations with public,
    // internal, private, internal protected, private protected...
}
Reasons:
  • Blacklisted phrase (0.5): I cannot
  • RegEx Blacklisted phrase (3): did you get
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Sergey A Kryukov