views:

123

answers:

2

I am trying out Resharper and i notice that it is recommending to set instance level fields to readonly. For example:

private readonly IConnection _connection;

public RetrieveCommand(IConnection connection) {
    _connection = connection;
}

What is the benefit of marking fields like this readonly?

+3  A: 

It marks it as readonly because the only place you assign the _connection member is in the contructor, which is the only place you are allowed to assigned a readonly member. see this article for an explanation

Colin