optional-parameters

Should you declare methods using overloads or optional parameters in C# 4.0?

I was watching Anders' talk about C# 4.0 and sneak preview of C# 5.0, and it got me thinking about when optional parameters are available in C# what is going to be the recommended way to declare methods that do not need all parameters specified? For example something like the FileStream class has about fifteen different constructors whi...

How do you use optional parameters in VB?

How can I create a method that has optional parameters in it in Visual Basic? ...

Is there a way to send optional parameters to an action?

Can I send optional parameters (empty strings, null int?'s etc) to an action through a GET request in asp.net mvc? (one sentence question!) ...

Optional Parameter in MVEL Functions

Is there a way to get MVEL 2.0 ( http://mvel.codehaus.org/ ) to work with functions with optional parameters? I would like to be able to eval this: trunc('blahblah',2) but also trunc('blahblah',2,'[...]'); Now i have tried: def trunc(param1,param2,param3) { ... impl ... } That gives an exception if i try to call it with only 3 pa...

are there PHP-like optional parameters in C#?

with PHP optional parameters, if you don't send a parameter it will be assigned to a default value: public function getCustomer(id, optionalMessage = "(no message)") { ... } in C# I generally solve this with C# method overloading, e.g.: public void GetCustomer(int id) { ... } public void GetCustomer(int id, string optional...

C# 4 optional parameter

Is C# 4 optional parameter implementation the same as VB.NET, the optional parameter is compiled on the call site(can cause versioning problems)? ...

Any way to specify optional parameter values in PHP?

Let's say I've got a PHP function foo: function foo($firstName = 'john', $lastName = 'doe') { echo $firstName . " " . $lastName; } // foo(); --> john doe Is there any way to specify only the second optional parameter? Example: foo($lastName='smith'); // output: john smith ...

Ruby optional parameters

If I define a Ruby functions like this: def ldap_get ( base_dn, filter, scope=LDAP::LDAP_SCOPE_SUBTREE, attrs=nil ) How can I call it supplying only the first 2 and the last args? Why isn't something like ldap_get( base_dn, filter, , X) possible or if it is possible, how can it be done? Thanks for any replies! ...

PHP Class construct with three optional parameters but one required?

So basically I understand this ... class User { function __construct($id) {} } $u = new User(); // PHP would NOT allow this I want to be able to do a user look up with any of the following parameters, but at least one is required, while keeping the default error handling PHP provides if no parameter is passed ... class User { ...

Is there an advantage to using parse_str for optional function parameters vs an array?

I happened to be making some changes to a WordPress blog and noticed that they use parse_str (http://php.net/parse_str) for parsing and setting their optional parameters to a function. I'm wondering if there is an advantage to this over sending an array? Examples: With array: $blahOptions = array( 'option_1' => true, ); BlahArra...

Named/optional parameters in Delphi?

In one of the Delphi demo applications, I've stumbled upon some syntax that I didn't know the Delphi compiler accepted: // ......\Demos\DelphiWin32\VCLWin32\ActiveX\OleAuto\SrvComp\Word\ // Main.pas, line 109 Docs.Add(NewTemplate := True); // note the assignment I can't seem to reproduce this type of parameter passing in my own c...

F#: Why can't I use optional parameters in loose functions?

Why can't I use optional parameters in loose functions defined with "let"? Why are they only allowed in member functions? ...

Java optional parameters

How do I use optional parameters in Java? What specification supports optional parameters? ...

Why can't typed optional arguments have a default of Null?

In ActionScript 3, when you declare an optional argument by giving it a default value, the value null cannot be used on typed arguments. function Action(Param:int=null){ // 1184: Incompatible default value of type Null where int is expected. } function Action(Param:int=0){ // No compiler errors } Any workarounds for this, or g...

Python - configuration options, how to input/handle?

When your application takes a few (~ 5) configuration parameters, and the application is going to be used by non-technology users (i.e. KISS), how do you usually handle reading configuration options, and then passing around the parameters between objects/functions (multiple modules)? Options examples: input and output directories/file ...

How would I skip optional arguments in a function call?

OK I totally forgot how to skip arguments in PHP. Lets say I have: checkbox_field ( $name, $value = '', $checked = false, $compare = '', $parameter = '' ) How would I call this function and skip the second last argument? checkbox_field('some name', 'some value', FALSE, '' , 'some parameter'); Would the above be correct? I c...

How to specify only some optional arguments when calling function in ColdFusion?

I have a ColdFusion function "foo" which takes three args, and the second two are optional: <cffunction name="foo" access="public" returntype="any"> <cfargument name="arg1" type="any" required="true" /> <cfargument name="arg2" type="any" required="false" default="arg2" /> <cfargument name="arg3" type="any" required="false" d...

Recommended initialization values for numbers

Assume you have a variety of number or int based variables that you want to be initialized to some default value. But using 0 could be problematic because 0 is meaningful and could have side affects. Are there any conventions around this? I have been working in Actionscript lately and have a variety of value objects with optional param...

How do i set an optional parameter in PHP after the first optional parameter

Hi I'm fairly new to php and I am trying to figure how do I set an optional parameter after the first optional parameter? For example I have the following code: function testParam($fruit, $veg='pota',$test='default test'){ echo '<br>$fruit = '.$fruit; echo '<br>$veg = '.$veg; echo '<br>Test = '.$test; } If i make the following calls...

Does C# 4.0 and a combination of optional parameters and overloads give you a warning about ambiguity?

I've started reading Jon Skeet's early access version of his book, which contains sections on C# 4.0, and one thing struck me. Unfortunately I don't have Visual Studio 2010 available so I thought I'd just ask here instead and see if anyone knew the answer. If I have the following code, a mixture of existing code, and new code: public v...