What does a readonly modifier for a method do?

129 views Asked by At

I write this code

struct Test
{
    public override string ToString()
        => "some text";
}

Then I get a compiler message suggestion IDE0251 Member can be made 'readonly'

this message is gone by applying readonly modifier as following

struct Test
{
    public override readonly string ToString()
        => "some text";
}

What this even mean? I don't see such case listed in readonly (C# Reference)

The closes case is with ref returns however the docs don't give me any clue what it means in above case.

Can any one state what a readonly here suppose to do?

0

There are 0 answers