Questions tagged [byref]
182 questions
4
votes
1 answer
COM Interop Method Signature with ByRef
I have a C# program that calls a COM DLL that has a method called test with two parameters: the first parameter is passed ByVal, the second one is passed ByRef.
This is what the COM DLL does:
Public Sub test(ByVal a As String, ByRef b As String)
…

CRK
- 337
- 2
- 10
4
votes
4 answers
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…

Dan Tao
- 125,917
- 54
- 300
- 447
4
votes
1 answer
Does F# have address-of & and pointer dereference * functions?
In C#, I write
unsafe void Main() {
float f = 3.14f;
int i = *(int*)&f;
}
Is it possible to translate this code to F#?
My understanding is that a pointer is represented by the nativeptr<'a> type, but I for the life of me I cannot find an…

kkm inactive - support strike
- 5,190
- 2
- 32
- 59
4
votes
1 answer
F# byref param not mutable
I need to assign to a byref parameter, but, using F# 4.0 and .NET 4.5.2 on a Windows 8x64 box, I keep getting complaints that This value is not mutable. I can't change the signature, because I'm implementing a COM interface. Minimal broken…

Jacob Manaker
- 723
- 4
- 17
4
votes
3 answers
ByRef vs ByVal performance when passing strings
Reading 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…

Clément
- 12,299
- 15
- 75
- 115
4
votes
3 answers
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 =…

Jelle De Loecker
- 20,999
- 27
- 100
- 142
4
votes
1 answer
Switching Byref to Byval on method calls VB.NET
Switching Byref to Byval on method calls
I have many warnings raised due to:
"Implicit conversion from xxxx to yyyy in copying the value of 'ByRef' parameter zzzz back to the matching argument."
My feeling is that it would be safe to change the…

acheo
- 3,106
- 2
- 32
- 57
4
votes
1 answer
Is it faster to transfer strings by reference between functions?
Is it better to transfer small or large strings by reference in C#? I assumed transferring by value would force the runtime to create a clone of the input string, and thus be slower. Is it recommended for all string functions to transfer values by…

Robin Rodricks
- 110,798
- 141
- 398
- 607
4
votes
1 answer
How to accept a function reference as an argument?
I'm currently passing a EventHandler object to a util function like this:
Timer newTimer(int interval, System.Timers.ElapsedEventHandler handler) {
....
timer.Elapsed += handler;
....
}
newTimer(1000, new…

Robin Rodricks
- 110,798
- 141
- 398
- 607
3
votes
5 answers
Invoke generic method with the generic type from a System.Type
below is a code example and the question, please note that I can NOT use C# 4.0 and the dynamic keyword.
static class TestClass
{
static void Main(string[] args)
{
Object o = "Previous value";
Test(ref o);
…

eq_
- 109
- 6
3
votes
3 answers
Classic asp: Function call by reference doesn't work with an array
I have an array witch I pass to a function by reference to sort it. However, seems like the array is passed byval. Can anyone solve what's the problem? (Also sort workarounds accepted)
1) The script below passes an array by-reference to the sort…

viljun
- 370
- 3
- 12
3
votes
2 answers
VBA ByRef argument type mismatch
Initially in my main code section I had an ugly if statement - though ugly it would run. I decided to make it a function that I would call, this caused me to get an error "Compile error: ByRef argument type mismatch". My assumption is that the…

John Higgs
- 33
- 1
- 5
3
votes
2 answers
Pass array created in first function to second function
This question is sort of built from my last question mainly because I want to avoid using Global variables because of its limitations. See answer to link here: How do I call upon an array created by a different function?
I'm attempting to use an…

Soto
- 75
- 2
- 9
3
votes
0 answers
F# compiler: A type instantiation involves a byref type
I have a problem and a solution. I don't understand why the solution works.
Here is some code that breaks the F# compiler with the message "A type instantiation involves a byref type":
let updateExternalLoginProperty(isEnabled: bool byref, value:…

Rob Lyndon
- 12,089
- 5
- 49
- 74
3
votes
1 answer
Why is this not a valid usage of byref?
let iter2D (map: 'T byref -> unit) (arr: 'T[][]) =
for y = 0 to arr.Length - 1 do
let row = arr.[y]
for x = 0 to row.Length - 1 do
let mutable elem = arr.[y].[x]
map &elem
The last line has: "The address…

Asik
- 21,506
- 6
- 72
- 131