Class Instantiation using WITH property argument - (Object Initilization)

disdp1

New member
Joined
Dec 29, 2011
Messages
1
Programming Experience
10+
I'm pretty sure that assigning properties in the with section of a class instantiation is BYVAL. Can anyone verify that?

ex) Dim FileProcess As New FileProcessor With {.Tracing = myTracing, .ProcessingTime = FileProcessingDelay}

I don't want to create a new object (.Tracing).

In the following example, I know for sure I'm passing in byref because that's the signature of the constructor.
ex) Dim FileProcess as new FileProcessor (myTracing) With {.ProcessingTime = FileProcessingDelay}


Public Class FileProcessor
Friend Sub New (byref Tracer as TraceObject)
End Sub
End Class

Regards,
Dave
 
You describe TraceObject as an object, and at the same time say it behaves like a value, which is it? I'm guessing you have wrongly defined TraceObject as a Structure, a value type.
Assignment always creates a copy, for value types it creates a copy of the value, for reference types it creates a copy of the reference.
About ByRef, that is a parameter passing mechanism which sole purpose is to enable the method to change the variable the caller passes in, be it a value or an object.
 
Back
Top