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

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.

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
231,268 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.

https://w.trhou.se/qvy4cumge6

here is my snapshot

1 Answer

Steven Parker
Steven Parker
231,268 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..

Thank you! you're a lifesaver!