Can't access method from one class in another even though it's set to public
Hi, I'm very new to C# and I'm currently making a small game for an assignment.
I have a class called Entity and another called EntityGroupTemplates, where I want to store a few methods that return a specific 2D array of Entity objects. The code for the templates class looks like this:
The issue that I am unable to call the entityGroupTemplateStart method to provide that 2D array, and I'm not sure why. I am trying to call it within the main Game1.cs (I'm using the Monogame engine for the project)
6 Replies
I'm not sure whywell how do you know that you're unable to call it?
It just doesn't appear as an option
if you type it out yourself, what happens?
Well now I feel silly
I completely forgot to instantiate the template class
It's working now after I did that
Ty for trying to help
haha sure thing
Your method is an instance method, so, as you concluded correctly, you can only call it on instances of your class. If you need more info, here are the docs:
https://learn.microsoft.com/en-us/dotnet/csharp/methods#method-invocation