Questions tagged [out-parameters]

145 questions
130
votes
10 answers

Why doesn't 'ref' and 'out' support polymorphism?

Take the following: class A {} class B : A {} class C { C() { var b = new B(); Foo(b); Foo2(ref b); // <= compile-time error: // "The 'ref' argument doesn't match the parameter type" } …
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360
108
votes
7 answers

Is there a VB.NET equivalent of C# out parameters?

Does VB.NET have a direct equivalent to C# out function parameters, where the variable passed into a function does not need to be initialised?
cspolton
  • 4,495
  • 4
  • 26
  • 34
89
votes
2 answers

Passing a property as an 'out' parameter in C#

Suppose I have: public class Bob { public int Value { get; set; } } I want to pass the Value member as an out parameter like Int32.TryParse("123", out bob.Value); but I get a compilation error, "'out' argument is not classified as a variable."…
thorncp
  • 3,587
  • 3
  • 24
  • 20
48
votes
2 answers

How can I invoke a method with an out parameter?

I want expose WebClient.DownloadDataInternal method like below: [ComVisible(true)] public class MyWebClient : WebClient { private MethodInfo _DownloadDataInternal; public MyWebClient() { _DownloadDataInternal =…
ldp615
  • 932
  • 1
  • 9
  • 13
45
votes
10 answers

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. …
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
41
votes
3 answers

Is there a way to omit out parameter?

Let's assume I have a function with out parameter, however I do not need its value. Is there a way to pass no actual parameter if given result will be thrown away anyway? EDIT: Although the question has been voted to be dupe of Optional Output…
konrad.kruczynski
  • 46,413
  • 6
  • 36
  • 47
19
votes
2 answers

passing out parameter

I wrote a method with an out parameter: -(NSString *)messageDecryption:(NSString *)receivedMessage outParam:(out)messageCondent { messageCondent = [receivedMessage substringFromIndex:2]; return [receivedMessage…
Vipin
  • 4,718
  • 12
  • 54
  • 81
19
votes
6 answers

Null out parameters in C#?

After reading on stackoverflow that in the case of checking the format of a DateTime you should use DateTime.TryParse. After trying some regex expressions they seem to get long and nasty looking to cover lots of the formatting. But TryParse requires…
chobo2
  • 83,322
  • 195
  • 530
  • 832
18
votes
2 answers

Fetch Oracle table type from stored procedure using JDBC

I'm trying to understand different ways of getting table data from Oracle stored procedures / functions using JDBC. The six ways are the following ones: procedure returning a schema-level table type as an OUT parameter procedure returning a…
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
18
votes
8 answers

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

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…
clickatwill
  • 950
  • 1
  • 10
  • 16
18
votes
6 answers

In what situations are 'out' parameters useful (where 'ref' couldn't be used instead)?

As far as I can tell, the only use for out parameters is that a caller can obtain multiple return values from a single method invocation. But we can also obtain multiple result values using ref parameters instead! So are there other situations where…
flockofcode
  • 1,799
  • 2
  • 12
  • 21
17
votes
2 answers

How to pass 'out' parameter into lambda expression

I have a method with the following signature: private PropertyInfo getPropertyForDBField(string dbField, out string prettyName) In it, I find the associated value prettyName based on the given dbField. I then want to find all properties, if any,…
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222
16
votes
3 answers

Out parameters in C

void swap(int &first, int &second){ int temp = first; first = second; second = temp; } int a=3,b=2; swap(a,b); The compiler complaints that void swap(int &first, int &second) has a syntax error. Why? Doesn't C support references?
user1128265
  • 2,891
  • 10
  • 29
  • 34
16
votes
2 answers

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…
John Feminella
  • 303,634
  • 46
  • 339
  • 357
15
votes
4 answers

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,…
Chris Ballance
  • 33,810
  • 26
  • 104
  • 151
1
2 3
9 10