Is there an expected return difference between the following two codes

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
 
G

Guest

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
 
A

academic

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
 
G

Guest

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
 
A

academic

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top