Is there any difference between accessing a property that has a backing field
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
versus an auto-property?
public int Id { get; set; }
The reason I'm asking is that when letting ReSharper convert a property into an auto property it seems to scan my entire solution, or at least all aspx-files.
I can't see any reason why there should be any difference between the two from outside the class. Is there?
The compiler generates the backing field for Auto-Properties automatically, so no, there shouldn't be any difference.
ReSharper is scanning all the files, because if you have a
Partial
class defined, it could be using the backing field instead of the public property even though the code exists in physically different files.For Example:
ReSharper must scan all files, since it has no way to know where a partial class might be defined.