AustinC
AustinC

Reputation: 169

Looping through a file of resources and loading them into an array

I am writing a program that calls for me to load in a series of images. I've created a file of images which I've embedded into the C# project. However, I haven't been able to find any suitable answer that will allow me to loop through these images and load them all into a data structure.

Is there a way to do this? I feel like this problem should require a simple fix, and that I may be overthinking it. Any help is appreciated, thanks!

Edit: In the interest of making my question any less vague, I'm trying to access my resource file named "GameBoardImages", which contains all of my images. I can access them one at a time, but have yet to figure out how to implement some mechanism that will allow me to loop through the GameBoardImages file and access and/or collect these images in order to store them into a data structure.

Using the assembly.GetManifestresourceNames() method, I get a list of resources such as: MyNameSpace.GameBoardImages.0800_GameBoardImage.png, MyNameSpace.GameBoardImages.0900_GameBoardImage.png, MyNameSpace.GameBoardIamges.1000_GameBoardImage.png, etc.

How do I loop through the entries in MyNameSpace.GameBoardImages?

Upvotes: 1

Views: 287

Answers (1)

Abion47
Abion47

Reputation: 24671

Give this a shot.

var images = Assembly.GetExecutingAssembly()
                     .GetManifestResourceNames()
                     .Where(x => x.EndsWith("_GameBoardImage.png"))
                     .ToList();

foreach (var img in images)
{
    // Do stuff...
}

Upvotes: 2

Related Questions