Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Using Task.Run() without Lamda

$
0
0

I'm not wild about Lambda expressions. I know how to use them but would like to be able to put a Func in the Task.Run(...) and keep the method itself separate. I just think that it would look cleaner. However, I'm struggling with the correct syntax (unless I'm trying to do the impossible).

I would like to place a Func that takes 2 double parameters and returns a double into a Task.Run. Here's what I have that doesn't work. Can anyone tell me what I need to do?

        public Func<double, double, double> poo = foo;

        public static double foo(double P1, double P2)
        {
            double val = P1 + P2;
            return val;
        }

        public Task<double> FooAsync(double P1, double P2)
        {
            return Task.Run(poo(P1, P2));
        }


Michael


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>