1

In VB.Net, I have an object named WorkflowButtonEventArgs that inherits from System.EventArgs.

The WorkflowButtonEventArgs class contains two ByRef Properties. These are objects that are in memory, and I do not want them duplicated or copied in any way.

Can I pass the WorkflowButtonEventArgs object ByVal in VB.Net and have it still preserve the two ByRef definitions in WorkflowButtonEventArgs?

Specifically, if I pass it ByVal:

Dim e As New WorkflowButtonEventArgs(...) ' e has some ByRef properties

RaiseEvent SomeEventName(e) ' e is passed ByVal

Will the ByRef Properties/Members in e (WorkflowButtonEventArgs class) not be copied or duplicated in memory?

Long-story-short: Can I pass e ByVal, or do I need to pass it ByRef since it contains ByRef Properties?

GSerg
  • 76,472
  • 17
  • 159
  • 346
  • By "ByRef" Property, do you mean a Property for a reference type, such as a Class? – rskar Dec 15 '11 at 19:50
  • What is a "ByRef" property? As far as I am aware, the ByRef keyword does not apply to properties nor can it be used when declaring a property. Can you be more specific? – Chris Dunaway Dec 15 '11 at 21:02

3 Answers3

1

Can I pass e "ByVal", or do I need to pass it "ByRef" since it contains "ByRef" Properties?

Yes. The objects pointed to by the reference will not get copied, even if your EventArgs is passed ByVal.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
1

Reference objects wont be duplicated in memory. The ByRef keyword on a parameter only means that you can change the value of a variable underlying the argument in the calling code.

Magnus
  • 45,362
  • 8
  • 80
  • 118
  • To All: My apologies for the error in the original post. The Properties are to Reference-type variables (specifically classes/objects). It sounds like I can pass the event arg "ByVal", and the reference-type Properties in the event arg will not be duplicated in memory. Sound right? – user1100622 Dec 15 '11 at 21:20
  • Reference objects wont be duplicated in memory. ByVal or ByRef does not matter – Magnus Dec 15 '11 at 21:22
  • Ok... that answers my question. Thanks to everyone. – user1100622 Dec 15 '11 at 22:05
0

Another way to achieve your goal would be to create a singleton that would store the two properties.

sfuqua
  • 5,797
  • 1
  • 32
  • 33