Questions tagged [byref]

182 questions
39
votes
7 answers

Which is faster? ByVal or ByRef?

In VB.NET, which is faster to use for method arguments, ByVal or ByRef? Also, which consumes more resources at runtime (RAM)? I read through this question, but the answers are not applicable or specific enough.
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
34
votes
3 answers

Why is it not necessary to indicate ByVal/ByRef anymore?

I just installed Visual Studio 2010 Service pack (proposed on Windows Update), and I can see a new feature on the "intellisense" that means when I write a Function or Sub in VB.NET it doesn't auto-complete parameters with ByRef or ByVal... 1) Is…
Yogurtu
  • 2,656
  • 3
  • 23
  • 23
28
votes
1 answer

Understanding byref, ref and &

Well, I came to understand that F# is able to manage references (some sort of C++ like references). This enables the possibilities to change value of parameters passed in functions and also enables the programmer to return more than a single…
Andry
  • 16,172
  • 27
  • 138
  • 246
25
votes
3 answers

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 Visual Basic 6.0, or is it just random? Also, how can I specify what to…
Jouke van der Maas
  • 4,117
  • 2
  • 28
  • 35
24
votes
3 answers

Doesn't C# Extension Methods allow passing parameters by reference?

Is it really impossible to create an extension method in C# where the instance is passed as a reference? Here’s a sample VB.NET console app: Imports System.Runtime.CompilerServices Module Module1 Sub Main() Dim workDays As Weekdays …
Jakob Gade
  • 12,319
  • 15
  • 70
  • 118
22
votes
4 answers

ByRef vs ByVal Clarification

I'm just starting on a class to handle client connections to a TCP server. Here is the code I've written thus far: Imports System.Net.Sockets Imports System.Net Public Class Client Private _Socket As Socket Public Property Socket As…
Brad
  • 159,648
  • 54
  • 349
  • 530
18
votes
10 answers

Best Practice: ByRef or ByVal? in .Net

What are the things to consider when choosing between ByRef and ByVal. I understand the difference between the two but I don't fully understand if ByRef saves resources or if we even need to worry about that in the .Net environment. How do you…
ctrlShiftBryan
  • 27,092
  • 26
  • 73
  • 78
17
votes
3 answers

VBA - Returning array from Property Get

If arrays are returned by reference, why doesn't the following work: 'Class1 class module Private v() As Double Public Property Get Vec() As Double() Vec = v() End Property Private Sub Class_Initialize() ReDim v(0 To 3) End Sub ' end class…
ThomasMcLeod
  • 7,603
  • 4
  • 42
  • 80
13
votes
1 answer

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…
Qwertie
  • 16,354
  • 20
  • 105
  • 148
12
votes
5 answers

How to get a value through a out/ref parameter from a method which throws an exception?

this code outputs "out value". class P { public static void Main() { string arg = null; try { Method(out arg); } catch { } Console.WriteLine(arg); } public static void Method(out string arg) { arg…
matarillo
  • 131
  • 3
9
votes
2 answers

Does specifying the OutAttribute on ByRef internal methods currently do anything?

VB.NET doesn't have out parameters, but you can specify ByRef on COM and P/Invoke methods to get the same effect for external methods. Does specifying the same on internal methods (i.e. methods only called by .NET code) actually help the…
Mark Hurd
  • 10,665
  • 10
  • 68
  • 101
9
votes
2 answers

Func(Of Tin, Tout) using a lambda expression with ByRef argument gives incompatible signature error

Why does this: Private [Function] As Func(Of Double, String) = Function(ByRef z As Double) z.ToString gives the following error: Nested function does not have a signature that is compatible with delegate String)'. While this: Private [Function]…
Brian Mulcahy
  • 1,453
  • 1
  • 16
  • 27
9
votes
2 answers

byref return in F# 4.5

I am trying to add a F#-style interface to a type, that has a byref return method. Here's the code: type IPool<'P, 'T when 'T: struct> = abstract member GetReference: ITypedPointer<'P, 'T> -> byref<'T> let Ref<'TPool, 'P, 'T when 'TPool :>…
LOST
  • 2,956
  • 3
  • 25
  • 40
9
votes
3 answers

F# member constraints + ^a byref parameters

After some playing around F# member constraints feature and writing function like this: let inline parse< ^a when ^a : (static member Parse: string -> ^a) > s = (^a: (static member Parse: string -> ^a) s) That works perfectly fine: let xs = […
controlflow
  • 6,667
  • 1
  • 31
  • 55
8
votes
5 answers

Passing string ByVal in VB.NET AND C#

So strings are reference types right? My understanding is a reference to the string in the heap is passed even when you pass the string ByVal to a method. Sooo..... String myTestValue =…
Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243
1
2 3
12 13