Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
4,968 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
4,968 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?