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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -