5

I have a bunch of pictures I'm using in a C# project, and I'm trying to initialize them all for later use. There are over 50 of them and they all have the same name format Properties.Resources._#, where # is the picture number. What I'm trying to do is something like:

for(int i = 0; i < 100; i++) {
   pics[i] = Properties.Resources._i;
}

How would I go about embedding the index into the name?

Thanks, and happy holidays.

EDIT: Just realized that if I had a way to embed the index in the name, I could just have a function that returns the specific picture based on the number given, so that would work too.

1 Answer 1

8

Like this:

 (Bitmap)Properties.Resources.ResourceManager.GetObject("_" + i)

Note that each call will read a separate copy of the bitmap, and will take time.
If you use the images frequently, pre-loading them into an array will make your program much faster.

Sign up to request clarification or add additional context in comments.

2 Comments

Cannot apply indexing with [] to an expression of type 'System.Resources.ResourceManager'. RecourceManager.getObject("_" + i) works though. Am I missing something?
@user: No; I was. Fixed; sorry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.