Is it possible that even if we pass arguments to the function but still we want to use default value only | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 5

Is it possible that even if we pass arguments to the function but still we want to use default value only

17th Jan 2017, 12:22 PM
N.Neeharika Reddy
N.Neeharika Reddy - avatar
3 Respostas
+ 1
define default value globally
18th Jan 2017, 2:17 AM
DHRUVIL LATHIYA
DHRUVIL LATHIYA - avatar
+ 1
Maybe add second argument with default value. But that would be confusing after revising the code after a while. So there are two ways - define variable inside function and add good comment to it so you temember why you did it or if it is an important value, make it public const or readonly variable.
19th Jan 2017, 1:27 AM
Jozef BlahĆŗt
Jozef BlahĆŗt - avatar
+ 1
This would probably be a good spot to have a compiler directive in place so you can test with it, but when you compile for production, you can use the passed in values instead. That way you can leave them on the code with comments and later disable them in one step, no matter how many there are. example: public void Some function(string paramA) { #if COMPILERVARIABLE paramA ="override value"; #endif //rest of function logic }
9th Feb 2017, 2:43 AM
Alan Kristensen