Skip to content
Sign upLog in
← Back to Community

public class not accessible C#

Profile icon
tothemax70

my repl tells me that my class player doesn't exist in the current context when i try to call it in a different class I've tried to get a reference to the player in the class but then it shows me
'''
Action.cs(6,22): error CS0051: Inconsistent accessibility: parameter type game.Player' is less accessible than methodgame.Action.CreateAction(game.Player)'
'''
any help will be appreciated

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
MrGerla
Profile icon
tothemax70
Comments
hotnewtop
Profile icon
Coder100

you put player inside a method. Other classes and methods won't be able to access it. Move it into the namespace or the class so you can either reference it directly or with respect to MainClass

Profile icon
SixBeeps

@Coder100
This, and also maybe make it static.

Profile icon
Coder100

@SixBeeps
oh right yeah i assumed that would be implicitly realized

Profile icon
SixBeeps

@Coder100
lol fair enough

Profile icon
SixBeeps

Player is private, but public. Make it public.

Profile icon
tothemax70

@SixBeeps
what do you mean private but public and how do i make it completely public?

Profile icon
SixBeeps

@tothemax70
Sorry, meant to type 'not' instead of 'but'. All you need to do to fix the error is to stick the word 'public' in front of class Player

Profile icon
tothemax70

@SixBeeps
just tried it and it gives me the same error message