C
C#12mo ago
Diesel Geezer

How to pass parameters to a Func

So i've made this function. I want to add paramters to it but i just can't figure it out
No description
17 Replies
Angius
Angius12mo ago
It's a Func with one generic parameter, which defines the return type It has no parameters If you want to add them... add them
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
Angius
Angius12mo ago
Func<int, int, bool> func = (intA, intB) => true;
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
Moods
Moods12mo ago
Put some generic parameters before the one you already did yeah Last one is the return type
Diesel Geezer
Diesel GeezerOP12mo ago
thank you all. I didn't know you have to put the parameter name between the 2 brackets
Diesel Geezer
Diesel GeezerOP12mo ago
No description
Diesel Geezer
Diesel GeezerOP12mo ago
btw is there any way to also pass a value to the parameter like that?
Diesel Geezer
Diesel GeezerOP12mo ago
No description
Angius
Angius12mo ago
I think you will need to type it (int foo = 0) => { ... } And at that point might as well use a var
var func = string (int foo = 0) => $"Number is {foo}";
var func = string (int foo = 0) => $"Number is {foo}";
I think it's a fairly new addition to the language, though
Moods
Moods12mo ago
You can specify return types for anonymous lambdas?
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
Moods
Moods12mo ago
Yeah I knew it was implicit i just didn’t know you could go string (int foo = 0) =>…
Angius
Angius12mo ago
You can, yeah
MODiX
MODiX12mo ago
Angius
REPL Result: Success
var func = string (int foo = 0) => $"Number is {foo}";
func(69)
var func = string (int foo = 0) => $"Number is {foo}";
func(69)
Result: string
Number is 69
Number is 69
Compile: 467.697ms | Execution: 73.448ms | React with ❌ to remove this embed.
Moods
Moods12mo ago
That’s cool as hell Learn something new everyday
Diesel Geezer
Diesel GeezerOP12mo ago
Great. 👍
Want results from more Discord servers?
Add your server