out-parameters

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

自作多情 提交于 2019-11-27 19:57:01
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." Is there any way to achieve this, or am I going to have to extract a variable, à la: int value; Int32.TryParse("123", out value); bob.Value = value; You'd have to explicitly use a field and "normal" property instead of an auto-implemented property: public class Bob { private int value; public int Value { get { return value; } set { this.value = value; }

How can I invoke a method with an out parameter?

Deadly 提交于 2019-11-27 18:43:10
I want expose WebClient.DownloadDataInternal method like below: [ComVisible(true)] public class MyWebClient : WebClient { private MethodInfo _DownloadDataInternal; public MyWebClient() { _DownloadDataInternal = typeof(WebClient).GetMethod("DownloadDataInternal", BindingFlags.NonPublic | BindingFlags.Instance); } public byte[] DownloadDataInternal(Uri address, out WebRequest request) { _DownloadDataInternal.Invoke(this, new object[] { address, out request }); } } WebClient.DownloadDataInternal has a out parameter, I don't know how to invoke it. Help! public class MyWebClient : WebClient {

How best to implement out params in JavaScript?

十年热恋 提交于 2019-11-27 15:30:55
问题 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

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

无人久伴 提交于 2019-11-27 08:10:00
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? No, there is no equivalent of the out keyword in VB. However, VB does automatically initialise all local variables in a method, so you can use ByRef without needing to explicitly initialise the variable first. Example: Sub Main() Dim y As Integer Test(y) End Sub Sub Test(ByRef x As Integer) x = 42 End Sub (If you examine code in the framework (for example Double.TryParse ), you may see the <OutAttribute> added to parameters, but that only makes a

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

走远了吗. 提交于 2019-11-27 06:55:16
问题 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.TryGetValue(key, out value); }); return got; } What's the best way to get this behavior? (Please refrain from providing advice on threadsafe dictionaries, this question is intended to

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

岁酱吖の 提交于 2019-11-26 22:52:59
问题 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." Is there any way to achieve this, or am I going to have to extract a variable, à la: int value; Int32.TryParse("123", out value); bob.Value = value; 回答1: You'd have to explicitly use a field and "normal" property instead of an auto-implemented property:

How can I invoke a method with an out parameter?

落花浮王杯 提交于 2019-11-26 22:43:20
问题 I want expose WebClient.DownloadDataInternal method like below: [ComVisible(true)] public class MyWebClient : WebClient { private MethodInfo _DownloadDataInternal; public MyWebClient() { _DownloadDataInternal = typeof(WebClient).GetMethod("DownloadDataInternal", BindingFlags.NonPublic | BindingFlags.Instance); } public byte[] DownloadDataInternal(Uri address, out WebRequest request) { _DownloadDataInternal.Invoke(this, new object[] { address, out request }); } } WebClient.DownloadDataInternal

Fetch Oracle table type from stored procedure using JDBC

不羁的心 提交于 2019-11-26 14:40:41
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 package-level table type as an OUT parameter procedure returning a package-level cursor type as an OUT parameter function returning a schema-level table type function returning a package-level table type function returning a package-level cursor type Here are some examples in PL/SQL: -- schema-level table type CREATE TYPE t_type AS OBJECT (val VARCHAR(4));

Why doesn&#39;t &#39;ref&#39; and &#39;out&#39; support polymorphism?

流过昼夜 提交于 2019-11-26 11:11:14
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" } void Foo(A a) {} void Foo2(ref A a) {} } Why does the above compile-time error occur? This happens with both ref and out arguments. Eric Lippert ============= UPDATE: I used this answer as the basis for this blog entry: Why do ref and out parameters not allow type variation? See the blog page for more commentary on this issue. Thanks for the great question. ============= Let's suppose you have classes Animal ,

Fetch Oracle table type from stored procedure using JDBC

对着背影说爱祢 提交于 2019-11-26 03:58:30
问题 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 package-level table type as an OUT parameter procedure returning a package-level cursor type as an OUT parameter function returning a schema-level table type function returning a package-level table type function returning a package-level cursor type Here