Solved

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

Posted on 2012-04-08
2
318 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Name space syntax error 12 41
Replace &lt; with < 14 56
C#  Radio button search for Date not DateTime 4 35
User Authentication using Digital Certificate 2 24
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

22 Experts available now in Live!

Get 1:1 Help Now