Questions tagged [out-parameters]
145 questions
14
votes
2 answers
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…

Zach Johnson
- 23,678
- 6
- 69
- 86
11
votes
5 answers
List as 'out' parameter causes an error. Why?
In this code:
public bool SomeMethod(out List tasks)
{
var task = Task.Factory.StartNew(() => Process.Start(info));
tasks.Add(task);
}
I get an error, "Use of unassigned out parameter 'tasks'". Why?
In an MSDN example there's just use…

Saint
- 5,397
- 22
- 63
- 107
11
votes
3 answers
How to create IN OUT or OUT parameters in Java
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]…

Lukas Eder
- 211,314
- 129
- 689
- 1,509
9
votes
5 answers
C#: can 'out' parameters in functions be object properties/variables?
C#: can 'out' parameters in functions be object properties/variables?
eg:
can I call a function as follows:
someFunction(x, y, out myObject.MyProperty1)

CJ7
- 22,579
- 65
- 193
- 321
9
votes
1 answer
DynamicMethod and out-parameters?
How do I define a DynamicMethod for a delegate that has an out-parameter, like this?
public delegate void TestDelegate(out Action a);
Let's say I simply want a method that sets the a argument to null when I call the method.
Note that I know that a…

Lasse V. Karlsen
- 380,855
- 102
- 628
- 825
8
votes
9 answers
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…

FP.
- 366
- 2
- 12
8
votes
4 answers
C#: How to use generic method with "out" variable
I want to create a simple generic function
void Assign(out T result)
{
Type type = typeof(T);
if (type.Name == "String")
{
// result = "hello";
}
else if (type.Name == "Int32")
{
// result = 100;
}
else result =…

Tin Vo
- 81
- 1
- 3
7
votes
2 answers
Java MyBatis stored procedure call with OUT parameters
First question:
I am trying to return one OUT parameter and not a result set with annotations. First, is it even possible? If it is, how would one do this?
MyBatis: 3.0.6
Database: SQL Server 2008
Here is an example of the syntax of my method call…

snoozy
- 133
- 2
- 2
- 4
7
votes
4 answers
What's the correct term for returning something as an out parameter?
I hope this question is on topic.
I was doing code review and stumbled upon the following function:
bool SomeFunc(std::string& o_xxx, char& o_yyy);
This function is used to retrieve the values of xxx and yyy of some class by means of out…

Armen Tsirunyan
- 130,161
- 59
- 324
- 434
7
votes
3 answers
Using TryGetValue() in LINQ?
This code works, but is inefficient because it double-lookups the ignored dictionary. How can I use the dictionary TryGetValue() method in the LINQ statement to make it more efficient?
IDictionary records = ...
IDictionary

Joe Daley
- 45,356
- 15
- 65
- 64
7
votes
2 answers
How can I implement the same behavior as Dictionary.TryGetValue
So, given then following code
type MyClass () =
let items = Dictionary()
do
items.Add ("one",1)
items.Add ("two",2)
items.Add ("three",3)
member this.TryGetValue (key,value) =
items.TrygetValue (key,value)
let c =…

pblasucci
- 1,738
- 12
- 16
7
votes
2 answers
RAII, unique_ptr, and out parameters
I'm a C# developer trying to learn C++11. I'm trying to query DNS using windns.h.
I started with DnsQuery() and read that I need to free the result records out parameter with DnsRecordListFree(). The C# way might be to use a try-finally block to…

Jason Kleban
- 20,024
- 18
- 75
- 125
6
votes
2 answers
Mixing Out and Named Parameters in C#: Why Does Out Parameter Need to be Named As Well?
Short Version: A named argument following an out argument gives a compiler error, but I cannot find any support for this behaviour in the language specification.
Long Version:
I'm using the Enum.TryParse three parameter overload, but I would…

Richard
- 106,783
- 21
- 203
- 265
6
votes
1 answer
c# generic delegate with out parameter - define and call
I'm currently refactoring an existing DAL which has a facade the user calls and an inner class that does the actual work dependent upon the ADO.Net provider to use e.g. SqlProvider, and I'm trying to ensure that code is DRY, I've done ok by using a…

Nathan
- 931
- 1
- 12
- 26
6
votes
3 answers
Which result pattern is best for a public API and why?
There are a few different common patterns for returning the result of a function call in public APIs. It is not obvious which is the best approach. Is there a general consensus on a best practice, or, at least convincing reasons why one pattern is…

smartcaveman
- 41,281
- 29
- 127
- 212