out-parameters

How to circumvent using an out parameter in an anonymous method block

The following method does not compile. Visual Studio warns "An out parameter may not be used within an anonymous method". The WithReaderLock(Proc action) method takes a delegate void Proc(). public Boolean TryGetValue(TKey key, out TValue value) { Boolean got = false; WithReaderLock(delegate { got = dictionary.TryGet...

C# Out parameter question: How does Out handle value types?

UPDATE So totally pulled a tool moment. I really meant by reference versus Out/Ref. Anything that says 'ref' I really meant by reference as in SomeMethod(Object someObject) Versus SomeMethod(out someObject) Sorry. Just don't want to change the code so the answers already make sense. Far as I understand, unlike ref where it "cop...

Should out params be set even if COM function fails?

When implementing a COM interface I always assign to the out parameters on success but should I do so also on error? HRESULT CDemo::Div(/*[in]*/ LONG a, /*[in]*/LONG b, /*[out,retval]*/ LONG* pRet) { if (pRet == NULL) return E_POINTER; if (b == 0) { *pRet = 0; // is this redundant? return E_INVALIDAR...

How should I check that [out] params in COM can be used?

Officially one should not use [out] parameters from COM functions unless the function succeeded this means that there are (at least) three ways to see if an [out] parameter can be used. Consider the following interface interface IFoo : IUnknown { HRESULT GetOtherFoo([out] IFoo** ppFoo); HRESULT Bar(); }; Which of the follow...

SubSonic: retrieving value of stored procedure OUT parameters

I love your tool. I have been using it a lot, but just today I ran into a problem... I wrote a stored procedure that returns some values via OUT parameters, but SubSonic does not seem to generate the out parametes of the stored procedure method. For example, for SPI like this: CREATE PROC dbo.MyProc @param1 int, @param2 int out, @param...

Code analysis comes back with suggestion about not using "out" parameters

I ran the VS 2008 code analysis tool against an object I created and received the following suggestion ... Warning 147 CA1021 : Microsoft.Design : Consider a design that does not require that 'returnValue' be an out parameter. I find "out" parameters rather useful and didn't realize that they were considered as a frowned upon...

ibatis in/out parameter problem

Can anyone tell me what's wrong? I have two procedures and two mappings for them. One works fine and another fails. This one works fine: <parameterMap id="mapping-descriptions" class="java.util.Map"> <parameter property="id" javaType="java.lang.Long" jdbcType="NUMBER" mode="IN"/> <parameter property="lang" javaType="java.l...

Why is an out parameter not allowed within an anonymous method?

This is not a dupe of Calling a method with ref or out parameters from an anonymous method I am wondering why out parameters are not allowed within anonymous methods. Not allowing ref parameters makes a bit more sense to me, but the out parameters, not as much. what are your thoughts on this ...

XPConnect (Firefox) - how to get value out of object

I'm trying to create a read from clipboard javascript function, and it's generally working, but I can't seem to extract the actual string from the object I create with the out parameter (Components.interfaces.nsITransferable). In case you're wondering, this is for a local intranet, and I have enabled clipboard access. This is the part o...

C#: How to use generic method with "out" variable

I want to create a simple generic function void Assign<T>(out T result) { Type type = typeof(T); if (type.Name == "String") { // result = "hello"; } else if (type.Name == "Int32") { // result = 100; } else result = default(T); } Usage: int value; string text; Assign(value); // <<< should set value to 100 ...

How to reflect on method with out params?

I am trying to get a MethodInfo object for a method on a type with an out param in its signature. Something to the effect of this: MethodInfo tryParse = typeof(T).GetMethod( "TryParse", BindingFlags.Public|BindingFlags.Static, null, new Type[] { typeof(string), typeof(T) }, null); But the problem is, it doesn't fin...

PL SQL - Return SQLCODE as OUT parameter is accepted ?

Hi, I have a procedure that returns an OUT parameter. procedure foo (in_v IN INTEGER, out_v OUT integer) BEGIN ... EXCEPTION WHEN OTHERS THEN --sh*t happend out_v := SQLCODE; END That parameter will be 0 if everything goes OK, and <> 0 if something ugly happened. Now, if sh*t happens along the way, an exception will be th...

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

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: p...

When is the value of a C# 'out' or 'ref' parameter actually returned to the caller?

When I make an assignment to an out or ref parameter, is the value immediately assigned to the reference provided by the caller, or are the out and ref parameter values assigned to the references when the method returns? If the method throws an exception, are the values returned? For example: int callerOutValue = 1; int callerRefValue...

How to avoid out parameters?

I've seen numerous arguments that using a return value is preferable to out parameters. I am convinced of the reasons why to avoid them, but I find myself unsure if I'm running into cases where it is unavoidable. Part One of my question is: What are some of your favorite/common ways of getting around using an out parameter? Stuff alon...

How many OUTPUT parameters can we declare for a stored procedure in SQL Server ?

How many OUTPUT parameters can we declare for a stored procedure in SQL Server ? ...

What is bad practice when using out parameters?

Are there any principles to keep in mind when using out parameters? Or can I look at them as just a good way to let a method return multiple values? What did the language designers have in mind when they were specifying the out parameter? Edit after some thought: As i'm thinking about it now, I would be inclined to say that excessive ...

How can I implement the same behavior as Dictionary.TryGetValue

So, given then following code type MyClass () = let items = Dictionary<string,int>() do items.Add ("one",1) items.Add ("two",2) items.Add ("three",3) member this.TryGetValue (key,value) = items.TrygetValue (key,value) let c = MyClass () let d = Dictionary<string,int> () d.Add ("one",1) d.Add ("two",2) d.Add ("th...

Patterns for simulating optional "out" parameters in C#?

I'm translating an API from C to C#, and one of the functions allocates a number of related objects, some of which are optional. The C version accepts several pointer parameters which are used to return integer handles to the objects, and the caller can pass NULL for some of the pointers to avoid allocating those objects: void initializ...

How best to implement out params in JavaScript?

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 ...