Passing a Method As an Argument To a Different Method

Updated on May 26, 2016 in [C] Intermediate
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
5 on May 26, 2016

Let’s write a challenge again, and this time not lose it… Yay…

So this is a thing I needed to do in one of my games and couldn’t find any solution online, so I did it myself and thought it might make for a good challenge. I hope you participate. šŸ˜‰

We all probably know you can’t put a method as a parameter in a method by just specifying the return type (including void) and then add parenthesis and maybe some parameters, just like you would do with a normal parameter. Most of us probably know about the “Func” delegate. But it isn’t enough, because you must have a return type that isn’t void. So you must figure it out yourself (I know it’s surprising, but there isn’t a solution online, at least not that I found). I don’t want you to just make an option to put a specific return typeĀ andĀ parameters amount/types, I want the option to put it as a parameter and only then specify the return type (there MUST be an option for void, the others are optional) and the parameters amount/type (each parameter should have a different custom type).

This is only a small challenge that came to my head while doing it myself, just for fun, so there won’t be anything like a time limit. You can just put your answer in the comments for that thread. Just make sure not to spoil the answer, so other people will be able to solve it themselves.
I thought about putting it as a beginners challenge, but then I thought about me doing it when I was a beginner and just…just no, please. It definitely isn’t advanced, because it only took me a few minutes to figure it out myself.
Please comment here to tell me if you will participate, because I would like to know how many people are joining. Please also tell me (reply to that thread) if I wasn’t specific enough about something, or you didn’t understand something, so I will be able to help. šŸ˜‰

  • Liked by
  • Dion Dokter
Reply
4 on May 26, 2016

Hmmm, I’ve been thinking about this. If I understand your challenge, then this should be the answer:

Click to Expand

Devoted
on May 26, 2016

I want to answer, but I forgot how to do that spoiler thingy… How do you do it?

Guru
on May 26, 2016

Just put ‘spoiler’ between the ‘[]”s and of course close it off with a /spoiler

Devoted
on May 26, 2016

Ok then.

Click to Expand
Guru
on May 26, 2016

Works too! šŸ˜‰

Show more replies
  • Liked by
Reply
Cancel