Is there an expected return difference between the following two codes

  • Thread starter Thread starter academic
  • Start date Start date
A

academic

Is there an expected difference between the following?

Stepping seems to show that the first way
GetContextMenuControlWindowsExplorer
does exhibit the correct data in this sub
But not in the calling routine.

The second way seems to work OK

Public ReadOnly Property GetContextMenuControlWindowsExplorer() As
ContextMenuStrip

Get

Dim tmp As ContextMenuStrip = New ContextMenuStrip

..snip

GetContextMenuControlWindowsExplorer = tmp THIS

Return tmp
OR THIS

End Get

End Property
 
When "Return..." is used, the property is immediately exited.
When you use method name assignment (unique to VB I think), the property
logic continues with code beyond the method name assignment - if another
method name assignment is made then the newer value is returned when the
property exits.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
But it would be surprising if different values are return from the two
methods, right?

I'm probably doing something dumb but it seems to me the Return returns what
I'd expect and the End Get seems to return an object that was just created.

Thanks
 
Are you sure that the "GetContextMenuControlWindowsExplorer = tmp" line is
being executed? The only way I can see the scenario you describe is if that
line doesn't execute.
I think it's better to use Return statements since they are less ambiguous.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
That's a thought.

Thanks

David Anton said:
Are you sure that the "GetContextMenuControlWindowsExplorer = tmp" line is
being executed? The only way I can see the scenario you describe is if
that
line doesn't execute.
I think it's better to use Return statements since they are less
ambiguous.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
Back
Top