.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Dealing with delegates

Posted By:Neet_Aarzoo       Posted Date: November 05, 2009    Points: 10    Category: Collections    URL: http://www.dotnetspark.com  
 

Delegate is similar to pointer.  You can call multiple function that have same argument through delegates.

Public Class sampleDelegate

Delegate Function mymethodDelegate(ByVal myint As Integer) As String

Public Class mysampleclass

Public Function myStringMethod(ByVal myint As Integer) As String

If myint > 0 Then

Return "Positive"

End If

If myint < 0 Then

Return "Negative"

End If

Return "Zero"

End Function

Public Function mysignMethod(ByVal myint As Integer) As String

If myint > 0 Then

Return "+"

End If

If myint < 0 Then

Return "-"

End If

Return "0"

End Function

End Class

Shared Sub main()

Dim ob As New mysampleclass

Dim ob1 As New mymethodDelegate(AddressOf ob.myStringMethod)

Dim ob2 As New mymethodDelegate(AddressOf ob.mysignMethod)

 

System.Console.WriteLine("Testing the Text Method using Delegates")

System.Console.WriteLine(ob1(5))

System.Console.WriteLine(ob1(-5))

System.Console.WriteLine("Testing the Sign Method using Delegates")

System.Console.WriteLine(ob2(5))

System.Console.WriteLine(ob2(0))

 

End Sub

End Class

 

regards

Neetu



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend