Questions tagged [parameters]

Parameters are a type of variable used in a subroutine to refer to the data provided as input to the subroutine.

A parameter is an intrinsic property of a procedure, included in its definition. For example, in many languages, a minimal procedure to add two supplied integers together and calculate the sum total would need two parameters, one for each integer. In general, a procedure may be defined with any number of parameters, or no parameters at all. If a procedure has parameters, the part of its definition that specifies the parameters is called its parameter list.

There are two ways of passing parameters to a procedure (both of them may not be available in every programming language):

  • by value: the value of a variable (or constant, etc.) is passed to the procedure and the original variable cannot be affected by the code in the procedure.
  • by reference: the reference to a variable is passed to a procedure and the variable's value can be changed in the procedure.
22681 questions
476
votes
21 answers

How to run an EXE file in PowerShell with parameters with spaces and quotes

How do you run the following command in PowerShell? C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe -verb:sync -source:dbfullsql="Data Source=mysource;Integrated Security=false;User ID=sa;Pwd=sapass!;Database=mydb;" -dest:dbfullsql="Data…
Vans
  • 4,769
  • 2
  • 16
  • 3
475
votes
4 answers

Passing a dictionary to a function as keyword parameters

I'd like to call a function in python using a dictionary with matching key-value pairs for the parameters. Here is some code: d = dict(param='test') def f(param): print(param) f(d) This prints {'param': 'test'} but I'd like it to just print…
Dave Hillier
  • 18,105
  • 9
  • 43
  • 87
462
votes
14 answers

How do Python functions handle the types of parameters that you pass in?

Unless I'm mistaken, creating a function in Python works like this: def my_func(param1, param2): # stuff However, you don't actually give the types of those parameters. Also, if I remember, Python is a strongly typed language, as such, it seems…
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
397
votes
15 answers

Assigning out/ref parameters in Moq

Is it possible to assign an out/ref parameter using Moq (3.0+)? I've looked at using Callback(), but Action<> does not support ref parameters because it's based on generics. I'd also preferably like to put a constraint (It.Is) on the input of the…
Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
396
votes
9 answers

In C#, what happens when you call an extension method on a null object?

Does the method get called with a null value or does it give a null reference exception? MyObject myObject = null; myObject.MyExtensionMethod(); // <-- is this a null reference exception? If this is the case I will never need to check my 'this'…
tpower
  • 56,100
  • 19
  • 68
  • 100
396
votes
11 answers

Why does a function with no parameters (compared to the actual function definition) compile?

I've just come across someone's C code that I'm confused as to why it is compiling. There are two points I don't understand. The function prototype has no parameters compared to the actual function definition. The parameter in the function…
AdmiralJonB
  • 2,038
  • 3
  • 23
  • 27
388
votes
18 answers

What is the "String args[]" parameter in the main method?

What does the following Java code mean? public static void main(String[] args) What is String[] args? When would you use these args? Source code and/or examples are preferred over abstract explanations.
freddiefujiwara
  • 57,041
  • 28
  • 76
  • 106
383
votes
4 answers

Getting list of parameter names inside python function

Is there an easy way to be inside a python function and get a list of the parameter names? For example: def func(a,b,c): print magic_that_does_what_I_want() >>> func() ['a','b','c'] Thanks
R S
  • 11,359
  • 10
  • 43
  • 50
373
votes
19 answers

Pass parameters in setInterval function

Please advise how to pass parameters into a function called using setInterval. My example setInterval(funca(10,3), 500); is incorrect.
Rakesh
  • 5,793
  • 8
  • 36
  • 37
361
votes
11 answers

Why use the params keyword?

I know this is a basic question, but I couldn't find an answer. Why use it? if you write a function or a method that's using it, when you remove it the code will still work perfectly, 100% as without it. E.g: With params: static public int…
MasterMastic
  • 20,711
  • 12
  • 68
  • 90
358
votes
8 answers

Use of "this" keyword in formal parameters for static methods in C#

I've come across several instances of C# code like the following: public static int Foo(this MyClass arg) I haven't been able to find an explanation of what the this keyword means in this case. Any insights?
kpozin
  • 25,691
  • 19
  • 57
  • 76
339
votes
17 answers

Get URL parameters from a string in .NET

I've got a string in .NET which is actually a URL. I want an easy way to get the value from a particular parameter. Normally, I'd just use Request.Params["theThingIWant"], but this string isn't from the request. I can create a new Uri item like…
Beska
  • 12,445
  • 14
  • 77
  • 112
338
votes
7 answers

Git alias with positional parameters

Basically I'm trying to alias: git files 9fa3 ...to execute the command: git diff --name-status 9fa3^ 9fa3 but git doesn't appear to pass positional parameters to the alias command. I have tried: [alias] files = "!git diff --name-status $1^…
user400575
  • 3,555
  • 2
  • 17
  • 11
332
votes
5 answers

Are parameters in strings.xml possible?

In my Android app I'am going to implement my strings with internationalization. I have a problem with the grammar and the way sentences build in different languages. For example: "5 minutes ago" - English "vor 5 Minuten" - German Can I do…
dhesse
  • 3,610
  • 2
  • 20
  • 12
311
votes
6 answers

Skip download if files already exist in wget?

This is simplest example running wget: wget http://www.example.com/images/misc/pic.png but how to make wget skip download if pic.pngis already available?
nais inpoh gan
  • 3,159
  • 2
  • 15
  • 5