Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Why did they do this ?


Reply
 
Thread Tools Display Modes
  #1  
Old 06-10-2012, 01:16 AM
philman philman is offline
Freshman
 
Join Date: Mar 2011
Posts: 32
Default Why did they do this ?


I have been going through a tutorial and came across this code:
Code:
Private Delegate Sub DisplayTextCallback(ByVal Text As String)
Private Sub CallDisplayTextCallback(ByVal Text As String)
        Dim cb As New DisplayTextCallback(AddressOf DisplayText)
        Dim args() As Object = {Text}  
        Me.Invoke(cb, args)
End Sub
I replaced the last 2 lines of the sub with:
Code:
Me.Invoke(cb, Text)
and it works perfectly.

Why did they create an object array?
Is it okay to use the "Text" keyword as a variable?

I would greatly appreciate any explanations.
Reply With Quote
  #2  
Old 06-10-2012, 06:36 AM
snarfblam's Avatar
snarfblam snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 866
Default

Just look at the documentation:
Code:
'Declaration
Public Function Invoke ( _
	method As Delegate, _
	ParamArray args As Object() _
) As Object
That "ParamArray" means that you can pass as many arguments as you wish, and they will automatically be placed in an array. That's what you did in your second code listing. Alternatively, you can explicitly create the array and pass it. That's what you did in your first code listing.

Quote:
Is it okay to use the "Text" keyword as a variable?
If you are asking if it's okay to use the Text variable as an argument, then yes, absolutely.
__________________
C# _VB.NET _
Reply With Quote
  #3  
Old 06-10-2012, 07:05 AM
philman philman is offline
Freshman
 
Join Date: Mar 2011
Posts: 32
Default

Thanks Snarfblam
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->