optional-parameters

The default value of an optional parameter must be constant

谁都会走 提交于 2020-08-10 23:08:09
问题 So Im creating this Event Tracker app and I have two screens which are the map and the events list. I am trying to get the place list to be equal to my places in my App state. Bare in mind that placeList is a modifiable list that I need to add places to this list. However I am getting a "The default value of an optional parameter must be constant" whenever I initialize this.places=PlaceMapState.placeList and I cant change it to a constant since i need it to update my list of places in the

Adding parameters to Runtime.getRuntime()?

对着背影说爱祢 提交于 2020-02-06 05:49:40
问题 void restartWeb() { try { String[] command = new String[] {"webRestarter.exe" , ">>","webLog.log"}; Runtime.getRuntime().exec(command); } catch (java.io.IOException err) { webServer.logError(err.getMessage()); } } Why doesn't this work? How could I fix it so it does work like I want it to? -- Executes webRestarter.exe with parameters >>webLog.log So it'd spit out something like this: webRestarter.exe>>webLog.log 回答1: You simply can't use pipes in a exec call. Pipes are a functionality of the

Adding parameters to Runtime.getRuntime()?

蹲街弑〆低调 提交于 2020-02-06 05:49:31
问题 void restartWeb() { try { String[] command = new String[] {"webRestarter.exe" , ">>","webLog.log"}; Runtime.getRuntime().exec(command); } catch (java.io.IOException err) { webServer.logError(err.getMessage()); } } Why doesn't this work? How could I fix it so it does work like I want it to? -- Executes webRestarter.exe with parameters >>webLog.log So it'd spit out something like this: webRestarter.exe>>webLog.log 回答1: You simply can't use pipes in a exec call. Pipes are a functionality of the

How would i use array_intersect() with the arrays in an array?

ぃ、小莉子 提交于 2020-01-25 22:43:47
问题 I have a dynamic amount of arrays in a specific array. Let's call this specific array: FatherArray This FatherArray has a dynamic amount of arrays in it, right now for example: Child1Array , Child2Array . Next time it gets called it could have more or less than those 2 Child(number)Arrays. So I want to use the function array_intersect() with the arrays (children) of FatherArray as parameters, so like array_intersect(Child1Array,Child2Array). I don't have a clue how i could do this dynamically

How would i use array_intersect() with the arrays in an array?

淺唱寂寞╮ 提交于 2020-01-25 22:41:59
问题 I have a dynamic amount of arrays in a specific array. Let's call this specific array: FatherArray This FatherArray has a dynamic amount of arrays in it, right now for example: Child1Array , Child2Array . Next time it gets called it could have more or less than those 2 Child(number)Arrays. So I want to use the function array_intersect() with the arrays (children) of FatherArray as parameters, so like array_intersect(Child1Array,Child2Array). I don't have a clue how i could do this dynamically

How can I create an optional DateTime parameter?

夙愿已清 提交于 2020-01-23 04:38:30
问题 I have this function that returns a reference type. Now, this function has two optional parameters both of which are instances of the DateTime class. The function is something like this: public DateTime GetDate(DateTime start = DateTime.MinValue, DateTime end = DateTime.MinValue) { // Method body... } The error from VS is: Default parameter value for 'start' must be a compile-time constant Of course, the error applies to the second parameter and I perfectly understand what is happening. What

Parameterized query with several optional search terms

柔情痞子 提交于 2020-01-14 01:59:30
问题 I have a web application with lots of data, and a search/filter function with several fields, such as name, status, date, and so on. I have been using parameterized queries like this for the regular (non-search) queries: $id = $_POST['itemID']; $db = mysqli_connect($host, $username, $password, $database); $sql_query = "SELECT * FROM tbl_data WHERE ID = ?"; $stmt_query = mysqli_prepare($db, $sql_query); mysqli_stmt_bind_params($stmt_query, "i", $id); mysqli_stmt_execute($stmt_query); //and so

Does optional parameter and optional attribute not supported together?

佐手、 提交于 2020-01-11 14:34:30
问题 public void ObjTest(StringBuilder sb, List<string> list, int i = 0, [Optional] string bs) { ...... } The above code throwing compilation error " Optional parameters must appear after all required parameters ". Does optional parameter and optional attribute not supported together in same method parameter, but it allows params arry after optional paramer ? 回答1: You can use them in conjunction but the optional parameter (the language construct) must be the last parameter in the parameter list.

Optional parameters and inheritance

孤人 提交于 2020-01-11 08:43:47
问题 I understand optional parameters, and I quite like them, but I'd just like to know a bit more about using them with an inherited interface. Exhibit A interface IMyInterface { string Get(); string Get(string str); } class MyClass : IMyInterface { public string Get(string str = null) { return str; } } Now I would've thought that the Get method in MyClass inherits both of the interface's methods, but... 'MyClass' does not implement interface member 'MyInterface.Get()' Is there a good reason for

Fortran 2003 / 2008: Elegant default arguments?

空扰寡人 提交于 2020-01-10 01:35:57
问题 In fortran, we can define default arguments. However, if an optional argument is not present, it can also not be set. When using arguments as keyword arguments with default values, this leads to awkward constructs like PROGRAM PDEFAULT CALL SUB CALL SUB(3) CONTAINS SUBROUTINE SUB(VAL) INTEGER, OPTIONAL :: VAL INTEGER :: AVAL ! short for "actual val" IF(PRESENT(VAL)) THEN AVAL = VAL ELSE AVAL = -1 ! default value END IF WRITE(*,'("AVAL is ", I0)') AVAL END SUBROUTINE SUB END PROGRAM PDEFAULT