C
C#12mo ago
wuqin

Problem with System.Action

Hi, I'm basically a newbie to coding and started a while ago to learn C# and English is not my national language so spare my grammar. I've been countering this for quite a while. Here's the situation : 1. my code didn't have any errors while debugging. 2. it throws an output System.Action while it is supposed to be a string that I created. 3. my code might look very messy and unorganized. Any tips may help a lot. 4. I didn't show every code inside cuz it will be very confusing. Basically when the user inputs a key, the minutes will increase and eventually the timer will increase. So I want the output to display the current time and current situation. 5. Any other suggestions or what I did wrong on the code are appreciated. 6. Here's the code : https://pastecode.io/s/oazco37d (I do not know the actual way to post my code since this is my first time posting) Thanks in advance to whoever uses their time to read this and try to help! You all are the greatest!
throws System.Action (oazco37d) - PasteCode.io
I didn't get any error and had searched for a while and couldn't get an answer.
4 Replies
Omnissiah
Omnissiah12mo ago
you can paste here the error anyway you are not calling the method this
Console.WriteLine("\nToilet System : " + timer.DisplayTime + situation);
Console.WriteLine("\nToilet System : " + timer.DisplayTime + situation);
should be this
Console.WriteLine("\nToilet System : " + timer.DisplayTime() + situation);
Console.WriteLine("\nToilet System : " + timer.DisplayTime() + situation);
if it returned a string but it doesn't...
Cattywampus
Cattywampus12mo ago
this part doesn't return string instead it updates the timer field
public void DisplayTime(){
timer = hours + "." + minutes;}
public void DisplayTime(){
timer = hours + "." + minutes;}
you can fix that by executing the timer.DisplayTime before printing and print the timer field instead
timer.DisplayTime();
Console.WriteLine("\nToilet System : " + timer.timer + situation);
timer.DisplayTime();
Console.WriteLine("\nToilet System : " + timer.timer + situation);
or change the the return type of the DisplayTime to string
public string DisplayTime(){
timer = hours + "." + minutes;
return timer;
}
//Then later on your can call it like this
Console.WriteLine("\nToilet System : " + timer.DisplayTimer() + situation);
public string DisplayTime(){
timer = hours + "." + minutes;
return timer;
}
//Then later on your can call it like this
Console.WriteLine("\nToilet System : " + timer.DisplayTimer() + situation);
wuqin
wuqinOP12mo ago
thanks! I didn't really see that I didn't add () there. Thanks for explaining! It makes it so clear now. Btw I couldn't return the value by adding timer but it works fine just doing return;, could you explain a bit?
Cattywampus
Cattywampus12mo ago
it should work if your change the void to string which is the same type as timer I already explained all of it above
Want results from more Discord servers?
Add your server