Click here to Skip to main content
15,881,600 members
Home / Discussions / C#
   

C#

 
GeneralRe: Open Browser, Wait for Callback Pin
Dave Kreskowiak20-May-23 4:16
mveDave Kreskowiak20-May-23 4:16 
GeneralRe: Open Browser, Wait for Callback Pin
Kevin Marois22-May-23 13:46
professionalKevin Marois22-May-23 13:46 
GeneralRe: Open Browser, Wait for Callback Pin
Dave Kreskowiak22-May-23 18:31
mveDave Kreskowiak22-May-23 18:31 
AnswerRe: Open Browser, Wait for Callback Pin
Pete O'Hanlon21-May-23 4:58
mvePete O'Hanlon21-May-23 4:58 
QuestionSame void between multiple forms in the same project? Pin
Member 1405587917-May-23 7:01
Member 1405587917-May-23 7:01 
AnswerRe: Same void between multiple forms in the same project? Pin
jschell17-May-23 7:29
jschell17-May-23 7:29 
AnswerRe: Same void between multiple forms in the same project? Pin
OriginalGriff17-May-23 7:54
mveOriginalGriff17-May-23 7:54 
QuestionFunc<> Question Pin
Kevin Marois3-May-23 18:48
professionalKevin Marois3-May-23 18:48 
Let's say that I have this Worker class which uses a Func to process data
public class Worker
{
    // Func to hold the method to run
    public Func&lt;int, List&lt;string&gt;&gt; DataSource { get; set; }

    // Method invokes the delegate
    public void Execute(int num) // &lt;==== I DON'T WANT TO PASS A PARAM HERE. 
    {
        var data = DataSource(num); //<== I'D LIKE TO SET THIS NUMBER OUTSIDE THIS CLASS

        data.ForEach(x =&gt; Console.WriteLine(x));
    }
}
I want to call a repository method using the func. Here's the repo method
public class Repo
{
    public List<string> GetData(int num)
    {
        var results = new List<string>();

        for (int x = 0; x < num; x++)
        {
            results.Add($"Result{x}");
        }

        return results;
    }
}
And here's the class that fires it all
internal class Program
{
    static void Main(string[] args)
    {
        // The Repo
        var repo = new Repo();

        // The Worker class
        var myClass = new Worker();

        // Assign the Repo method to the Worker class
        myClass.DataSource = repo.GetData;

        // Call the worker class's Execute, passing in the number
        // of results to get back
        myClass.Execute(10);

        Console.ReadLine();
    }
}

Here's the question...

How would I code this so that I wouldn't have to pass in the param to Execute? Can I define the Func with the param as part of it? Maybe something like:
// Assign the Repo method to the Worker class
myClass.DataSource = repo.GetData(10);  // <===== PASS PARAM HERE

I don't want to have to pass any parameters into the Worker class. Can the func somehow accept parameters?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.


modified 4-May-23 0:58am.

AnswerRe: Func<> Question Pin
Richard Deeming3-May-23 21:47
mveRichard Deeming3-May-23 21:47 
GeneralRe: Func<> Question Pin
Kevin Marois4-May-23 5:57
professionalKevin Marois4-May-23 5:57 
SuggestionRe: Func<> Question Pin
BillWoodruff26-May-23 19:56
professionalBillWoodruff26-May-23 19:56 
QuestionXML validation with Schematron Pin
antann781-May-23 0:56
antann781-May-23 0:56 
AnswerRe: XML validation with Schematron Pin
jschell1-May-23 11:21
jschell1-May-23 11:21 
QuestionHow to "Reach" content of an XML node/tag (and turn it into a new reader) Pin
pr1mem0ver20-Apr-23 3:30
pr1mem0ver20-Apr-23 3:30 
AnswerRe: How to "Reach" content of an XML node/tag (and turn it into a new reader) Pin
Gerry Schmitz22-Apr-23 5:34
mveGerry Schmitz22-Apr-23 5:34 
AnswerRe: How to "Reach" content of an XML node/tag (and turn it into a new reader) Pin
lmoelleb24-Apr-23 5:18
lmoelleb24-Apr-23 5:18 
GeneralRe: How to "Reach" content of an XML node/tag (and turn it into a new reader) Pin
pr1mem0ver7-Jul-23 22:46
pr1mem0ver7-Jul-23 22:46 
Question405 Error for WebSocket with WSS but not WS (ASP.Net) Pin
Gwyll14-Apr-23 4:20
Gwyll14-Apr-23 4:20 
AnswerRe: 405 Error for WebSocket with WSS but not WS (ASP.Net) Pin
OriginalGriff14-Apr-23 6:00
mveOriginalGriff14-Apr-23 6:00 
GeneralRe: 405 Error for WebSocket with WSS but not WS (ASP.Net) Pin
Gwyll14-Apr-23 7:53
Gwyll14-Apr-23 7:53 
GeneralRe: 405 Error for WebSocket with WSS but not WS (ASP.Net) Pin
jschell14-Apr-23 11:38
jschell14-Apr-23 11:38 
AnswerRe: 405 Error for WebSocket with WSS but not WS (ASP.Net) Pin
Gwyll14-Apr-23 12:43
Gwyll14-Apr-23 12:43 
QuestionHow to get XSI:type in inner class while converting to XML Pin
dineshrastogi14-Apr-23 1:42
dineshrastogi14-Apr-23 1:42 
AnswerRe: How to get XSI:type in inner class while converting to XML Pin
Pete O'Hanlon14-Apr-23 2:05
mvePete O'Hanlon14-Apr-23 2:05 
QuestionC# List of Tasks Pin
Kevin Marois6-Apr-23 19:07
professionalKevin Marois6-Apr-23 19:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.