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
Angius5mo 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 User5mo ago
Message Not Public
Sign In & Join Server To View
Angius
Angius5mo ago
Func<int, int, bool> func = (intA, intB) => true;
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Moods
Moods5mo ago
Put some generic parameters before the one you already did yeah Last one is the return type
Diesel Geezer
Diesel Geezer5mo ago
thank you all. I didn't know you have to put the parameter name between the 2 brackets
Diesel Geezer
Diesel Geezer5mo ago
No description
Diesel Geezer
Diesel Geezer5mo ago
btw is there any way to also pass a value to the parameter like that?
Diesel Geezer
Diesel Geezer5mo ago
No description
Angius
Angius5mo 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
Moods5mo ago
You can specify return types for anonymous lambdas?
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Moods
Moods5mo ago
Yeah I knew it was implicit i just didn’t know you could go string (int foo = 0) =>…
Angius
Angius5mo ago
You can, yeah
MODiX
MODiX5mo 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
Moods5mo ago
That’s cool as hell Learn something new everyday
Diesel Geezer
Diesel Geezer5mo ago
Great. 👍