Click here to Skip to main content
15,906,106 members
Home / Discussions / C#
   

C#

 
GeneralRe: ConcurrentList<T> Pin
BillWoodruff22-May-23 11:38
professionalBillWoodruff22-May-23 11:38 
GeneralRe: ConcurrentList<T> Pin
Gerry Schmitz22-May-23 12:06
mveGerry Schmitz22-May-23 12:06 
AnswerRe: ConcurrentList<T> Pin
Richard Deeming21-May-23 21:05
mveRichard Deeming21-May-23 21:05 
GeneralRe: ConcurrentList<T> Pin
Richard Andrew x6422-May-23 6:28
professionalRichard Andrew x6422-May-23 6:28 
GeneralRe: ConcurrentList<T> Pin
Richard Deeming22-May-23 20:40
mveRichard Deeming22-May-23 20:40 
AnswerRe: ConcurrentList<T> Pin
jschell22-May-23 7:11
jschell22-May-23 7:11 
AnswerRe: ConcurrentList<T> Pin
lmoelleb26-May-23 2:55
lmoelleb26-May-23 2:55 
GeneralRe: ConcurrentList<T> Pin
Richard Andrew x6431-May-23 13:22
professionalRichard Andrew x6431-May-23 13:22 
QuestionOpen Browser, Wait for Callback Pin
Kevin Marois19-May-23 6:43
professionalKevin Marois19-May-23 6:43 
AnswerRe: Open Browser, Wait for Callback Pin
Dave Kreskowiak19-May-23 7:08
mveDave Kreskowiak19-May-23 7:08 
GeneralRe: Open Browser, Wait for Callback Pin
Kevin Marois19-May-23 8:12
professionalKevin Marois19-May-23 8:12 
GeneralRe: Open Browser, Wait for Callback Pin
Gerry Schmitz19-May-23 8:46
mveGerry Schmitz19-May-23 8:46 
GeneralRe: Open Browser, Wait for Callback Pin
Dave Kreskowiak19-May-23 10:51
mveDave Kreskowiak19-May-23 10:51 
GeneralRe: Open Browser, Wait for Callback Pin
Gerry Schmitz20-May-23 4:00
mveGerry Schmitz20-May-23 4:00 
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 

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.