Solved

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

Posted on 2012-04-08
2
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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