C
C#6mo 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
WEIRD FLEX
WEIRD FLEX6mo 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
Cattywampus6mo 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
wuqin6mo 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
Cattywampus6mo 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
More Posts
How do I use a string from one class to another?```c# using System; using System.Net.Http; using System.Threading.Tasks; public class Keys { publHow can I reference a Blazor Hybrid project’s form or component in WinForms?I’ve created a Blazor Hybrid project and referenced it in a WinForms project, but the styles are nothow to handle big float numbers without bugging?basicly as it shows the big, it kinda bugs doing such conversion, the point is on wrong place and it✅ Updating MigrationsFrom my understanding Migrations are the code for EF to create a SQL DB. Ive followed this crash couAny tips for someone beginner to learn ASP.NET MVC CoreI have done a few minor "projects" but am just looking to see if anyone has any tips on how to get bCan't see Histogram instrument tagI'm creating a `Histogram<double>` instrument through `IMeterFactory.CreateHistogram<double>(...)` aIs it possible to build a custom Expression<Func<T, bool>> by chaining "Or" operations to use in EF?Hi all, this is my first post here. I want to check if it's possbile to chain Expression.Or operatioSystem.Net.ServicePointManager.CloseConnection MissingWhat verion of System.Net has "void System.Net.ServicePointManager.CloseConnectionGroups(string)", iWhy is my list output not using the method to check true/false``` public class InterfacePA { public static void Main(string[] args) { Console.Writ✅ Is this a correct way or I just mad things wrong?Hi friends, hope you're doing well, I'm working on a project which using `CQRS` with `MediatR`, I h