public class Foo
{
private readonly Bar _bar;
}
public class Foo2
{
private Bar _bar;
}
I don’t see any benefit to marking it as readonly. It’s private and if I try do something internally to modify it it’s me being dumb since I know how I want my class to behave? So, what’s the point? I don’t think there is any performance gain here, so that can’t be it.
It’s always nice to have the compiler prevent you from being dumb.
It’s especially nice to have the compiler prevent other people from being dumb, even if they’re not familiar with the codebase.
It also serves to tell other people reading your code that the field will never change