I don’t use prefix while naming internal variables of a class (I know some do but I am not starting ‘why do you…’ debate). I just prefer it that way. The problem is that sometimes same parameters are passed in contructor and I end up being confused how to name them. For example:
public class SampleClass { private int classId; private string className; public SampleClass (int XclassIdX, string XclassNameX) { classId = XclassIdX; className = XclassNameX; } }
How to name XclassIdX and XclassNameX?
One thing that can probably be done is:
public class SampleClass { private int classId; private string className; public SampleClass (int classId, string className) { this.classId = classId; this.className = className; } }
Just not sure whether this is a good idea or there are other more elgant ways?
I think the solution you’re describing, where the constructor parameters are identically named and you prefix the class members with
this, is just fine. It’s clear, it’s concise, and there is no confusion about what you meant.