optional-parameters

java optional parameters [duplicate]

与世无争的帅哥 提交于 2020-01-02 05:40:12
问题 This question already has answers here : Java optional parameters (17 answers) Closed 6 months ago . I want to write an average method in java such that it can consume N amount of items, returning the average of them: My idea was: public static int average(int[] args){ int total = 0; for(int i=0;i<args.length;i++){ total = total + args[i]; } return Math.round (total/args.length); } //test it average(1,2,3) // s**hould return 2. how can I change my method to consume any amount of parameters

Oracle SQL - How to build where clause with optional search parameters

非 Y 不嫁゛ 提交于 2020-01-02 04:34:09
问题 There are four field in the page lets say EMPLOYEE ID DEPT LOCATION UNIT: User might enter any of the field values all are optional, if he enter EMPLOYEE ID then the query should return rows related to that EMPLOYEE ID . If he enters only LOCATION then the query should return all the employees of that location. How to write the where clause condition with optional parameters. 回答1: Oracle will likely build a well-optimized query if you use NVL in your predicates: select * from employee where

ReSharper: Find Usages of an optional parameter

非 Y 不嫁゛ 提交于 2020-01-02 00:52:28
问题 If I have a function with optional parameter, is there an easy way to find all the locations in my code that call that function and pass a value to that parameter? The function has many non-default parameters, so scanning the usual Find Usages results of places that call the function is problematic, as it trims the lines and I can't see if the optional parameter is used. 回答1: With your cursor on the parameter, choose ReSharper | Inspect | Value Origin , or from the keyboard, Inspect This with

Function overloading vs Optional Parameters

倾然丶 夕夏残阳落幕 提交于 2020-01-01 12:11:13
问题 So I'm just thinking about function overloading... Overloaded methods share the same name but have a unique signature. The number of parameters, types of parameters or both must be different. A function can't be overloaded on the basis of a different return type alone. So in the following example, why overload setName rather than use optional parameters for the middle and last name values? class funOverload { public string name; //overloaded functions public void setName(string last) { name =

Suppress candidates suggested by GCC

末鹿安然 提交于 2019-12-30 09:40:12
问题 I'm using gcc 4.7.2. My code is rather heavy on template and boost usage. When I compile and I've defined or used something ambiguous, I often get error messages that suggest two dozen candidates, usually defined in their separate "in file included from [some deep path]:", with corresponding error messages per candidate on why that particular candidate fails. Especially using boost and templates, even a single error like this becomes completely unintelligible. My question: Is there an option

How to skip optional parameters in C#?

a 夏天 提交于 2019-12-29 05:39:07
问题 Example: public int foo(int x, int optionalY = 1, int optionalZ = 2) { ... } I'd like to call it like this: int returnVal = foo(5,,8); In other words, I want to provide x and z , but I want to use the default for Y , optionalY = 1. Visual Studio does not like the ,, Please help. 回答1: If this is C# 4.0, you can use named arguments feature: foo(x: 5, optionalZ: 8); See this blog for more information. 回答2: In C# 4.0 you can name the arguments occurring after skipped defaults like this: int

WCF and optional parameters

老子叫甜甜 提交于 2019-12-29 05:06:31
问题 I just started using WCF with REST and UriTemplates. Is it now possible to use optional parameters? If not, what would you guys recommend I do for a system that has three parameters that are always used in the url, and others that are optional (varying amount)? Example: https://example.com/?id=ID&type=GameID&language=LanguageCode&mode=free id, type, language are always present mode is optional 回答1: I just tested it with WCF 4 and it worked without any problems. If I don't use mode in query

Optional Template parameter

时间秒杀一切 提交于 2019-12-29 04:29:06
问题 Is it possible to have optional template parameter in C++ , for example template < class T, class U, class V> class Test { }; Here I want user to use this class either with V or without V Is following possible Test<int,int,int> WithAllParameter Test<int,int> WithOneMissing If Yes how to do this. 回答1: You can have default template arguments, which are sufficient for your purposes: template<class T, class U = T, class V = U> class Test { }; Now the following work: Test<int> a; // Test<int, int,

Passing an empty array as default value of an optional parameter [duplicate]

[亡魂溺海] 提交于 2019-12-27 11:47:12
问题 This question already has answers here : Setting the default value of a C# Optional Parameter (3 answers) Closed 6 years ago . How does one define a function that takes an optional array with an empty array as default? public void DoSomething(int index, ushort[] array = new ushort[] {}, bool thirdParam = true) results in: Default parameter value for 'array' must be a compile-time constant. 回答1: You can't create compile-time constants of object references. The only valid compile-time constant

Entity Framework Linq Is Null, Is Not Null Issue

99封情书 提交于 2019-12-24 20:40:15
问题 I have a method that receives a category id, followed by two optional string parameters that default to null. I tried using a few similar answers from other questions on SO but sofar none have helped. I am trying to get the linq to EF query to work as follows: If either optional parameter has a value, use the value otherwise use an Is Null. If both optional parameters are present use these as part of the query or either one if only on eis supplied. But if no parmeters are added, just use the