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# Objects Methods Using Static Methods

Erik Hainer
Erik Hainer
3,049 Points

Console.WriteLine not printing to console

I've been using the Treehouse Workspaces to code, and unfortunately for the past few hours it just has not been printing to Console, when i use Console.WriteLine. I get no errors but it will not print. I'm not sure what to do.

Erik Hainer
Erik Hainer
3,049 Points

here is my main code:

using System;
namespace TreehouseDefense
{
    class Game
    {
       public static void Main()
        {
          Map map = new Map(8, 5);

          Point point = new Point(4, 2);

          Console.WriteLine(point.DistanceTo(5,5));
        }
    }
}

here is my Point File

using System;
namespace TreehouseDefense
{
  class Point
  {
   public readonly int X;
   public readonly int Y;

   public Point (int x, int y)
    {
      X = x;
      Y = y;
    }

    public int DistanceTo(int x, int y)
    {
      int xDiff = X - x;
      int yDiff = Y - y;
      int xDiffSquared = xDiff * xDiff;
      int yDiffSquared = yDiff * yDiff;

      return (int)Math.Sqrt(xDiffSquared + yDiffSquared);
    }

  }
}

To run and compile, I type in console: mcs -out:TreehouseDefense *.cs && mono TreehouseDefense.exe

when i type ls into console, i receive: Game.cs Map.cs Point.cs TreehouseDefense.Exe Invader.cs Path.cs Tower.cs

Steven Parker
Steven Parker
216,012 Points

It would help to have access to the entire workspace to replicate the issue.
Take a look at this video about sharing a snapshot of your workspace.

1 Answer

Steven Parker
Steven Parker
216,012 Points

It was all in the commands, but I didn't notice until I tried them in the snapshot:   :see_no_evil:

mcs -out:TreehouseDefense *.cs:point_left: this creates an output file named "TreehouseDefense"
  && mono TreehouseDefense.exe:point_left: but this runs a file named "TreehouseDefense.exe"

if you run mono TreehouseDefense instead, you'll get the expected output.

There was no error because an old file (that did not output anything) named "TreehouseDefense.exe" was already present in the directory..

Erik Hainer
Erik Hainer
3,049 Points

Thank you! you're a lifesaver!