• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

Delegates return value / Delegates does not return value - C#/VB.NET

Hi,

Can you please provide me examples on:

Delegates return value / Delegates does not return value - C#/VB.NET

Thanks
0
milani_lucie
Asked:
milani_lucie
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Could you be a little more specific as to the conditions of your error?

Here's a simple example of a delegate being used to return a value:
Public Class Form1

    Public Delegate Function ReturnReversedString(ByVal input As String) As String

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim msg As String = "Hello World!"

        Dim rrs As New ReturnReversedString(AddressOf ReverseString)
        msg = rrs(msg)
        MessageBox.Show(msg)
    End Sub

    Private Function ReverseString(ByVal input As String) As String
        Dim sb As New System.Text.StringBuilder
        For i As Integer = input.Length - 1 To 0 Step -1
            sb.Append(input.Substring(i, 1))
        Next
        Return sb.ToString
    End Function

End Class

Open in new window

0
 
BuggyCoderCommented:
Action and its other generic Equivalents are the ones that return no value
Func and its other generic equivalents are the ones that return value

Its preferred that you use one of them rather than creating your own.

Here are the examples:-
http://www.claassen.net/geek/blog/2007/12/action-func-never-write-another.html
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now