Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics Methods Methods

For the Methods video on the C# Basics course, running my code does not show anything in the console

I input the same code as the instructor's into my Workspace but when I run my code, nothing happens. The instructor's video shows "Welcome to the cat food store!" but my code, when I type "dotnet run" into the Console, shows absolutely nothing. Is my code missing something, or is this a bug?

Thanks

3 Answers

Simon Coates
Simon Coates
8,177 Points

Are you running in workspaces? Are you able to post the URL to a snapshot or post your code. If people can't see your code then it's tricky to see if there's anything up. However, as a demo, I entered

using System;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Welcome to the cat food store!");
        System.Threading.Thread.Sleep(3000);
        Console.WriteLine("done sleeping.");
    }
}

I saved and ran "dotnet run". Output was:

treehouse:~/workspace$ dotnet run                                              
Welcome to the cat food store!                                                 
done sleeping.                                                                 

So the code associated with that video seems to work.

Hi Simon,

Thanks for your reply. I took a snapshot of the workspace here

I ran it again and nothing shows up in the console.

Thank you!

Simon Coates
Simon Coates
8,177 Points

when I look at that workspace program.cs currently is listed as:

class Program
{
    static void Main(string[] args)
    {

    }
}

If you think there's a problem saving your code (under file on the menu structure) you can view the code you're executing via the console. eg.

treehouse:~/workspace$ cat Program.cs                                                                          
class Program                                                                                                  
{                                                                                                              
    static void Main(string[] args)                                                                            
    {                                                                                                          

    }                                                                                                          
}                                                                                                              
treehouse:~/workspace$ dotnet run                                                                              
treehouse:~/workspace$ 

Hi Simon,

You solved my problem. Turns out the code was not being automatically saved. So going forward, I need to manually save any code that is input before running it in the Console?