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