c# - Defining Constants by Scope -
i've been in habit of defining constants @ class level:
public class myclass { private const int somenumber = 10; ... }
but, worked believes if constant used specific method should defined in method:
public class myclass { public void somemethod() { const int somenumber = 10; ... } }
my argument preferring first if constant needed in other methods there no refactoring needed , makes easier update constants since they'll defined in same place.
are there other pros/cons or there no real difference?
if needs updating it's not constant. mean, don't refactor value of pi. things change belong in configuration file in opinion.
that said, use class level public constants. i've never seen or used method-level constants. conceptually, method level constant makes little sense me.
Comments
Post a Comment