C
C#2w ago
Sayoregg

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:
internal class EntityGroupTemplates
{
public Entity[,] entityGroupTemplateStart()
{
Entity[,] template = new Entity[8, 12];

///Code to fill 2D array

return template;
}
}
internal class EntityGroupTemplates
{
public Entity[,] entityGroupTemplateStart()
{
Entity[,] template = new Entity[8, 12];

///Code to fill 2D array

return template;
}
}
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
mg
mg2w ago
I'm not sure why
well how do you know that you're unable to call it?
Sayoregg
SayoreggOP2w ago
It just doesn't appear as an option
mg
mg2w ago
if you type it out yourself, what happens?
Sayoregg
SayoreggOP2w ago
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
mg
mg2w ago
haha sure thing
SleepWellPupper
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
Want results from more Discord servers?
Add your server