byref

VB6 COM returns ADODB.Recordset in byRef Variant. How to retrieve in C#?

I'm trying to call this COM method: Public Function DoSomething(ByRef StringStuff As Variant, **ByRef Out_Data As Variant**) As Boolean Out_Data gets defined and populated in the method body as an ADODB.Recordset (2.6). I've tried several different ways I can think of, but still can't seem to get that recordset object out, or in for...

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

Powershell / .Net: Get a reference to an object returned by a method

I am teaching myself PowerShell by writing a simple parser. I use the .Net framework class Collections.Stack. I want to modify the object at the top of the stack in place. I know I can pop() the object off, modify it, and then push() it back on, but that strikes me as inelegant. First, I tried this: $stk = new-object Collections.Sta...

Reflection: How to get the underlying type of a by-ref type

I was surprised to learn that "ref" and "out" parameters are not marked by a special attribute, despite the existence of ParameterInfo.IsOut, ParameterInfo.IsIn (both of which are always false as far as I can see), ParameterAttributes.In and ParameterAttributes.Out. Instead, "ref" parameters are actually represented by a special kind of ...

How to 'do' ByVal in C#

As I understand it, C# passes parameters into methods by reference. In vb.net, you can specify this with ByVal and ByRef. The default is ByVal. Is this for compatibility with vb6, or is it just random? Also, how can I specify what to use in C#? I kind of like the idea of passing parameters by value. ...

Python access an object byref / Need tagging

I need to suck data from stdin and create a object. The incoming data is between 5 and 10 lines long. Each line has a process number and either an IP address or a hash. For example: pid=123 ip=192.168.0.1 - some data pid=123 hash=ABCDEF0123 - more data hash=ABCDEF123 - More data ip=192.168.0.1 - even more data I need to put this data...

Make object not pass by reference

I just found out the hard way objects are passed by reference in Javascript, for example: for(var layer = 0; layer < hudLayers['layers'].length; layer++){ // Store the to-be-calculated values in this object var tempValues = hudLayers['layers'][layer]; tempValues['name'] = 'test'; } This will change the value in tempValue...

[VB.Net] ByRef vs ByVal performance when passing strings

Hello everyone! Reading http://stackoverflow.com/questions/408101/which-is-faster-byval-or-byref made me wonder whether the comments in there did apply to Strings in terms of performance. Since strings are copied before being passed, isn't it much more efficient (if the callee doesn't need a copy of string course) to pass strings ByRef?...

Why is it legal to pass "Me" ByRef in VB.NET?

I was shocked just a moment ago to discover that the following is legal (the C# equivalent is definitely not): Class Assigner ''// Ignore this for now. Public Field As Integer ''// This part is not so weird... take another instance ByRef, ''// assign it to a different instance -- stupid but whatever. ' Sub Assign(By...

Differences between address-of and ref operators

In my code I'm passing around some structures by reference, declaring them mutable and using the & symbol. The problem is that in some place the fields are corrupted (happens only in release mode) and I don't know absolutely why. I have found a fix, using ref keyword instead of the address-of operator. I understand that you can intercha...