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 Encapsulation and Arrays Ternary If

Jason Rice
Jason Rice
6,657 Points

Error with accessibility

I'm getting this error:

treehouse:~/workspace$ mcs -out:TreehouseDefense.exe *.cs && mono TreehouseDefense
Path.cs(9,12): error CS0051: Inconsistent accessibility: parameter type TreehouseDefense.MapLocation[]' is less accessible than methodTreehouseDefense.Path.Path(TreehouseDefense.MapLocation[])'
MapLocation.cs(3,11): (Location of the symbol related to previous error)
Path.cs(14,24): error CS0050: Inconsistent accessibility: return type TreehouseDefense.MapLocation' is less accessible than methodTreehouseDefense.Path.GetLocationAt(int)'
MapLocation.cs(3,11): (Location of the symbol related to previous error)

Jason Rice
Jason Rice
6,657 Points

Path.cs = using System;

namespace TreehouseDefense { public class Path { private readonly MapLocation[] _path;

public Path(MapLocation[] path)
{
  _path = path;
}

public MapLocation GetLocationAt(int pathStep)
{
  /*if(pathStep < path.Length)
  {
  return _path[pathStep];
  }
  else
  {
    return null;
  }*/
  return (pathStep < path.Length) ? _path[pathStep] : null;
}

} }

2 Answers

Steven Parker
Steven Parker
230,248 Points

Part of the issue is in a module not shown here. But just guessing from the error message, I might speculate that on line 3 of MapLocation.cs there's a missing "public" directive.

To facilitate a complete and accurate analysis in multi-source projects like this, make a snapshot of your workspace and post the link to it here.

Steven Parker
Steven Parker
230,248 Points

I guessed it! The snapshot confirms that line 3 of MapLocation.cs needs a "public" access modifier.

Also, on line 16 of Path.cs the term "path.Length" is missing an underscore (should be "_path.Length").

Steven Parker
Steven Parker
230,248 Points

That helps! I added a comment to my answer.

Jason Rice
Jason Rice
6,657 Points

That worked! Thank you very much for your help!! They probably should add that to video! Inserting public before class in line 3 of MapLocation.cs