Home > other >  Block.Tile Positions () is unavailable due to its security level
Block.Tile Positions () is unavailable due to its security level

Time:05-21

I have TilePositions() component and when i tried change it from private to public i'm generic new error which is: "Accessibility inconsistency, the return type "IEnumerable " is less accessible than the "Block.TilePositions ()" method "

here's photos: Block.cs class, GameGrid.cs class

and that's when i change it to public: Block.cs calss, GameGrid.cs class

public abstract class Block
    {
        Position[][] Tiles { get; }  
        Position StartOffset { get; }    
        public abstract int Id { get; }

        private int rotationState;
        private Position offset;


        public Block()
        {
            offset = new Position(StartOffset.Row, StartOffset.Column);
        }


        private IEnumerable<Position> TilePositions() //here is error
        {
            foreach (Position p in Tiles[rotationState])
            {
                yield return new Position(p.Row   offset.Row, p.Column   offset.Column);
             
            }
        }
}
private bool BlockFits()
        {
            foreach (Position p in CurrentBlock.TilePositions())
            {
                if (!GameGrid.IsEmpty(p.Row,p.Column))
                {
                    return false;
                }
            }
            return true;
        }

CodePudding user response:

Change private to public for access from out object.

 public IEnumerable<Position> TilePositions() //here is error
    {
        foreach (Position p in Tiles[rotationState])
        {
            yield return new Position(p.Row   offset.Row, p.Column   offset.Column);
         
        }
    }

public : In c#, the public modifier is used to specify that access is not restricted, so the defined type or member can be accessed by any other code in the current assembly or another assembly that references it.

private : In c#, the private modifier is used to specify that access is limited to the containing type, so the defined type or member can only be accessed by the code in the same class or structure.

  • Related