C#
C#

help

Root Question Message

Azurely
Azurely12/25/2022
❔ Is it possible to put a method into a variable and call the variable?

like this:
Azurely
Azurely12/25/2022
Or atleast something similar to that
Angius
Angius12/25/2022
A static method, yes
Angius
Angius12/25/2022
A non-static method, no
Angius
Angius12/25/2022
But why do you want to do that here? You can just get the value from this method and print that
Azurely
Azurely12/25/2022
I'm just messing around and trying to learn things
Azurely
Azurely12/25/2022
not for any particular reason
mtreit
mtreit12/25/2022
That's not exactly true, as long as you have an instance.
Angius
Angius12/25/2022
Huh
Angius
Angius12/25/2022
TIL
Angius
Angius12/25/2022
Thought Funcs and Actions need to be static
mtreit
mtreit12/25/2022
Nope 🙂
Azurely
Azurely12/25/2022
isn't that basically what I'm doing?
Azurely
Azurely12/25/2022
not sure why it might not be working for me
mtreit
mtreit12/25/2022
Paste your full code
Orannis
Orannis12/25/2022
You're invoking aMethod
Orannis
Orannis12/25/2022
With the () after the name
Azurely
Azurely12/25/2022
Orannis
Orannis12/25/2022
So var method is the thing that aMethod() returns, not aMethod itself
Orannis
Orannis12/25/2022
You want var method = Object.aMethod; (note the lack of parentheses)
Azurely
Azurely12/25/2022
Oh I see
Azurely
Azurely12/25/2022
i'm basically doing () twice
mtreit
mtreit12/25/2022
Presumably that code doesn't even compile since aMethod takes an int and you aren't passing one
Azurely
Azurely12/25/2022
although it's telling me this now
Azurely
Azurely12/25/2022
Orannis
Orannis12/25/2022
Are you using .NET Framework?
Angius
Angius12/25/2022
I started assuming everybody with the green mark next to their name is using Framework lol
Angius
Angius12/25/2022
Microsoft should really hid the (.NET Framework) templates from VS
mtreit
mtreit12/25/2022
Legacy codebases are a huge part of the ecosystem
Angius
Angius12/25/2022
Legacy stuff is already on Framework, no new projects to be made
Angius
Angius12/25/2022
Besides, not saying remove it completely, just slap it into some "show more" dropdown
mtreit
mtreit12/25/2022
I agree if you are creating brand new .NET Framework projects that will not be referenced by other .NET Framework projects you should reconsider your life choices.
Azurely
Azurely12/25/2022
it's not vs
Azurely
Azurely12/25/2022
it's w3schools code executer lol
Angius
Angius12/25/2022
Why
Azurely
Azurely12/25/2022
if i'm going to use vs, what template should I use if I just want to mess around and run random things?
Angius
Angius12/25/2022
$newproject
Azurely
Azurely12/25/2022
sick
Angius
Angius12/25/2022
The console will be good for starters
mtreit
mtreit12/25/2022
If you use $code (not screenshots) to paste your exact source code that is failing it will be a lot more clear what the issue you are seeing is.
Azurely
Azurely12/25/2022
what's the difference between WPF application and console application?
Angius
Angius12/25/2022
WPF has all the windows and buttons and text inputs and stuff
Angius
Angius12/25/2022
Console is... console
Angius
Angius12/25/2022
Just the text
mtreit
mtreit12/25/2022
Well, unless you go for something like https://github.com/gui-cs/ 🙂
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy