out-parameters

Why don't anonymous delegates/lambdas infer types on out/ref parameters?

筅森魡賤 提交于 2019-12-03 06:07:58
Several C# questions on StackOverflow ask how to make anonymous delegates/lambdas with out or ref parameters. See, for example: Calling a method with ref or out parameters from an anonymous method Write a lambda or anonymous function that accepts an out parameter To do so, you just need to specify the type of the parameter, as in: public void delegate D(out T p); // ... D a = (out T t) => { ... }; // Lambda syntax. D b = delegate(out T t) { ... }; // Anonymous delegate syntax. What I'm curious about is why the type is explicitly required. Is there a particular reason that this is the case?

Parameter in C#

℡╲_俬逩灬. 提交于 2019-12-02 18:56:31
问题 When I want get total value of memory in C# I found a kernel32 function in MSDN to invoke data from system. MSDN declare function this way: [return: MarshalAs(UnmanagedType.Bool)] [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer); but this don't work correctly. I change "ref" to "[In, Out]" then it work correctly. How can tell me what is [In, Out] parameters in C#? 回答1: In: http://msdn.microsoft.com/de

Parameter in C#

六月ゝ 毕业季﹏ 提交于 2019-12-02 11:41:56
When I want get total value of memory in C# I found a kernel32 function in MSDN to invoke data from system. MSDN declare function this way: [return: MarshalAs(UnmanagedType.Bool)] [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer); but this don't work correctly. I change "ref" to "[In, Out]" then it work correctly. How can tell me what is [In, Out] parameters in C#? In: http://msdn.microsoft.com/de-de/library/system.runtime.interopservices.inattribute.aspx Out: http://msdn.microsoft.com/de-de/library

How to create IN OUT or OUT parameters in Java

穿精又带淫゛_ 提交于 2019-12-01 15:54:28
In PL/SQL (or many other languages), I can have IN OUT or OUT parameters, which are returned from a procedure. How can I achieve a similar thing in Java? I know this trick: public void method(String in, String[] inOut, String[] inOut2) { inOut[0] = in; } Where the in parameter represents an IN parameter and the inOut parameter can hold a return value. The convention would be that String[] inOut is an array of inOut.length == 1 . That's kind of clumsy. EDIT Feedback to answers : Other tricks include: holder/wrapper classes, but I don't want to introduce any new types, callbacks, etc. return

PHP - MySQL gets value of out parameter from a stored procedure

南楼画角 提交于 2019-12-01 00:17:38
I have called a MySQL stored procedure from PHP using mysqli . This has one out parameter. $rs = $mysqli->query("CALL addNewUser($name,$age,@id)"); Here, @id is the out parameter. Next, I fire the following query to get the value of the out parameter: $rs2 = $mysqli->query("SELECT @id"); while($row = $rs->fetch_object()){ echo var_dump($row); } The output of var_dump is as follows. object(stdClass)#5 (1) { ["@id"]=> string(6) "100026" } So, now I want to retrieve the value of @id , which I am unable to. I tried $row[0]->{@id} but this gave following error: PHP Fatal error: Cannot use object of

PHP - MySQL gets value of out parameter from a stored procedure

余生长醉 提交于 2019-11-30 19:17:13
问题 I have called a MySQL stored procedure from PHP using mysqli . This has one out parameter. $rs = $mysqli->query("CALL addNewUser($name,$age,@id)"); Here, @id is the out parameter. Next, I fire the following query to get the value of the out parameter: $rs2 = $mysqli->query("SELECT @id"); while($row = $rs->fetch_object()){ echo var_dump($row); } The output of var_dump is as follows. object(stdClass)#5 (1) { ["@id"]=> string(6) "100026" } So, now I want to retrieve the value of @id , which I am

Real-world examples where C# 'out' parameters are useful?

强颜欢笑 提交于 2019-11-30 06:49:55
I'm reading up on core C# programming constructs and having a hard time wrapping my head around the out parameter modifier. I know what it does by reading but am trying to think of a scenerio when I would use it. Can someone give me a real-world example? Thanks. there are many scenarios where you would use it, but the main one would be where your method needs to return more then one parameter. Take, for example, the TryParse methods on int type. In this case, instead of throwing an exception a bool is returned as a success/failure flag and the parsed int is return as the out param. if you were

MyBatis annotations to call Stored Procedure and get Out Params

拟墨画扇 提交于 2019-11-29 16:04:07
I am using MyBAtis-3 with MyBAtis-Spring. When i tried to call a stored procedure that returns more than one out params using MyBatis annotations. I don't get anything, I can see that the input parameter is passed to the SP in the logs and it hangs in there with no progress nor exception thrown. PFB the Oracle Stored Procedure which i am trying to access from MyBAtis, create or replace PROCEDURE C2C.GET_DATA ( "IN_PARAM1" IN NUMBER, "OUT_PARAM2" OUT SAMPLETABLE.COL2%TYPE, "OUT_PARAM3" OUT SAMPLETABLE.COL3%TYPE, "OUT_PARAM4" OUT SAMPLETABLE.COL4%TYPE ) AS BEGIN SELECT PARAM2,PARAM3,PARAM4 INTO

How best to implement out params in JavaScript?

点点圈 提交于 2019-11-29 00:59:03
I'm using Javascript with jQuery. I'd like to implement out params. In C#, it would look something like this: /* * odp the object to test * error a string that will be filled with the error message if odp is illegal. Undefined otherwise. * * Returns true if odp is legal. */ bool isLegal(odp, out error); What is the best way to do something like this in JS? Objects? function isLegal(odp, errorObj) { // ... errorObj.val = "ODP failed test foo"; return false; } Firebug tells me that the above approach would work, but is there a better way? The callback approach mentioned by @Felix Kling is

MyBatis annotations to call Stored Procedure and get Out Params

大城市里の小女人 提交于 2019-11-28 09:27:39
问题 I am using MyBAtis-3 with MyBAtis-Spring. When i tried to call a stored procedure that returns more than one out params using MyBatis annotations. I don't get anything, I can see that the input parameter is passed to the SP in the logs and it hangs in there with no progress nor exception thrown. PFB the Oracle Stored Procedure which i am trying to access from MyBAtis, create or replace PROCEDURE C2C.GET_DATA ( "IN_PARAM1" IN NUMBER, "OUT_PARAM2" OUT SAMPLETABLE.COL2%TYPE, "OUT_PARAM3" OUT