FAQ Database Discussion Community


Practical Reasons to use C# “named arguments”

c#,methods,parameters,arguments,optional-parameters
I find this feature "named arguments" from C# to be really weird because I see two flaws from it. The book says "named arguments give you the "ability to pass arguments in any order". Two flaws I think is a problem for this C# feature: It violates "information hiding" in...

How to specify a variadic (ellipsis) parameter as optional in Swift?

ios,swift,optional-parameters,variadic-functions
Is it possible to have a variadic parameter be optional in Swift? I tried the two ways that made sense and neither compile: func myFunc(queryFormat: String?...) { } or func myFunc(queryFormat: String...?) { } Note: The 1st implementation technically compiles but if you try to unwrap it: if let queryFormatUnwrapped...

Calling a method with optional parameters from a string

c#,.net,methods,invoke,optional-parameters
I have multiple methods, some with optional parameters and some without any. How can i call those methods by only having the function name as a string? Currently i have this: public Method method = Method.QuickSort; public enum Method { BubbleSort, MergeSort, QuickSort, InsertionSort, RadixSortLSD, CocktailSort, CombSort, OddEvenSort } MethodInfo...

Get number of formal parameters in PHP

php,optional-parameters
I know you can use func_num_args to get the number of actual arguments passed in. Is there any way to get the number of formal parameters? Example: <?php function optional($a, $b = null) { echo func_num_args(); } optional(1); // 1 optional(1, 1); // 2 optional(1, 1, 1); // 3 I...

forward pipe tuple to a method with optional params

f#,optional-parameters
I got piece of code like this: type x() = member x.f(number:int, ?text:string) = "doesn't matter" let instance = new x() let result = instance.f(1, "s") This works fine, but as I was doing some refactoring I've found, that the following won't even compile. let param = (1,"s") let result2...

“Constant Expression required” Exception thrown when using Optional Parameters [duplicate]

.net,vb.net,exception,colors,optional-parameters
This question already has an answer here: Using Color As Optional Parameter In a function within a class 3 answers I get a "Constant Expression required" exception when running this Sub Procedure; Public Sub SolidFill(Optional SolidColor As Color = Color.Black) .... End Sub However, this happens only when using...

Is Call MagicFunction(intData1, intData2, Dim intData3) a valid statement in vbs?

vbscript,optional-parameters
I'm not really sure how to phase it any other way. The thing is, i'm trying to merge functions with the same name in vbs. Sometimes, the function appears in different forms in other parts of the system. If they are too different, I regretfully leave them as they are....

SSRS Parameters - Toggle a parameter's NULL checkbox depending on value other parameter(s) NULL checkboxes

reporting-services,parameters,toggle,optional-parameters
In MS SQL Server Report Builder 3.0, I have an SSRS report with 3 parameters: start date (date) end date (date) last number of days (integer) My Stored Procedure needs either a Date Range OR the last number of days, not all 3 (they are set to NULL by default)....

C# Interface, Unity, and Optional Parameter

c#,interface,optional-parameters
Hopefully someone can shed some light on this one. I have an interface with an optional parameter. We use Unity. If I try to change the optional parameter in the method implementation, it works directly, but the Unity object uses the interface's default - not the implemented method's default. Setup:...

Python - how to set default parameter equal to another parameter

python,default,optional-parameters
I have a function, which should have one optional parameter. I want the optional parameter to be the same as other parameter. Something like this: def foo(arg1, arg2, src, dst=src): ... ... Parameter dst is the optional one. The thing is when dst is not given when calling foo, it...

python argparse always set defaults related to an optional argument

python,default,argparse,optional-parameters
I use python 3, i want to set argparse to always set the default key in relation to a predefined optional argument of my choice. E.g. I pass some input files to the script. An optional argument specify if the input file should be rotated by the script. I get...

VBA Function Optional parameters

vba,function,optional-parameters
I am calling a specific piece of code several times therefore I would like to use optional parameters. I can write something like: Public Sub main() strA = "A" 'Calling the function CalculateMe (strA) End Sub Public Sub CalculateMe(strA As String) Set rs = DB.OpenRecordset("tbl_A") rs.MoveFirst Do Until rs.EOF If...

Optional output cursor as parameter

oracle,parameters,cursor,default-value,optional-parameters
I'm trying to cater for two applications. One calls a procedure with 2 cursors, the other with 1. Both are OUT SYS_REFCURSOR. Because of the difference in definition of the procedure, the change to one application will break the other. I am wondering if its possible to have the same...

Swift Optionals(?). What's the difference between two?

swift,syntax,nil,optional-parameters,optional
In terms of the optionals(?), what's the difference between the two? I'm trying to pick up swift and it seems that the location of "?" matters and i'm having a hard time grasping the effect of having "?" in different places. var beaconGroup:GroupData = filteredArray.firstObject? as GroupData var beaconGroup:GroupData =...

How to make function argument optional in PHP?

php,function,argument-passing,optional-parameters,default-arguments
Suppose following is my function definition: public function addPhotoFeed($val) { ----------------------------- ------------------------------ ----------------------------- } In above function $val is an array that is passed as an argument to the same. Now I want to call the above function when I don't pass any argument. So how should I call it?...

Setting random values to unassigned/optional parameters

java,parameters,optional-parameters
I am building a tiled map generator application and I want users to be able to set subareas of a map to be a specific type of tile when building it. This is currently implemented like this: public boolean setArea(int bottomLeftX, int bottomLeftY, int subWidth, int subHeight, TerrainType aAreaType){ boolean...

Java: Parameter list without comma

java,methods,parameters,optional-parameters
I came across a method with a parameter list where the parameter were not separated by comma and no declaration of the variable type: public int compareWith(Choice anotherChoice){ Later these parameters were called without any further declaration inside the body in an if-else statement in combination with another method: if...

Is it possible to restrict the values of optional parameters in C#?

c#,default-value,optional-parameters
C# allows the use of optional parameters: one can specify the value in case the parameter is omitted in a call and the compiler then specifies the value itself. Example: public interface IFoo { void SomeMethod (int para = 0); } This idea is useful but a problem is that...