Solved

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

Posted on 2012-04-08
2
317 Views
Last Modified: 2012-06-27
Hi,

Can you please provide me examples on:

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

Thanks
0
Comment
Question by:milani_lucie
2 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 37822377
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
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37822516
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now