Static function parameters vs static data member


New member
Nov 14, 2017
Programming Experience
Hi,A silly question but would like to get this clarified .We know that the static data members share the values and do not lose the value irrespective of how many instances are created by the class (as they are not bound to the instance)How are the parameters of a static function treated. Means if I call a static function 100 times , passing different or same values each time to the parameters, will it cause any issues.Though I think that this should be perfectly fine as I don't think that parameters of a static function will retain their values across multiple function calls as they are local to the function but again the function is static.A bit of confusion.regards,Amit
A static function only returns value once it is called, no value is stored for functions, as far as I know there is also no memory allocation for static functions.
I think that you're looking at this the wrong way. Think about how a field/property work and think about how a method works. A field/property is somewhere to store data. It has a default value based on its type and if you put a value in then that value sits in the field/property and you can access that value any time until it is set again. A method is behaviour rather than data. You call a method and the system creates a stack frame that basically contains the parameters as local variables. When the method returns, the stack frame is cleaned up and your method call disappears.

None of that changes because the field/property or method is static. The only difference between static members and instance members is that they belong to the type instead of an instance of the type. A field/property is still a place to store data and a method is still behaviour that doesn't occupy memory until you call it, at which point a stack frame is created containing the parameters as local variables.
Top Bottom