0

If I declare a struct like this:

public record struct MyStruct(bool MyValue);

and then look at the decompiled source, it looks like this:

public struct MyStruct : IEquatable<MyStruct>
{
    [CompilerGenerated]
    private bool <MyValue>k__BackingField;

    public bool MyValue
    {
        [IsReadOnly]
        [CompilerGenerated]
        get
        {
            return <MyValue>k__BackingField;
        }
        [CompilerGenerated]
        set
        {
            <MyValue>k__BackingField = value;
        }
    }

    public MyStruct(bool MyValue)
    {
        <MyValue>k__BackingField = myValue;
    }

<etc>

How do I prevent the compiler from adding the set to MyValue property?

I would expect that changing it to:

public record struct MyStruct(in bool myValue);

would indicate that I want it to be readonly but this doesn't seem to make a difference

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.