C # Resource Array

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

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

How do I enable index embedding in a name?

Thank you and happy holidays.

EDIT: I just realized that if I had a way to insert an index into the name, I could just have a function that returns a specific image based on the specified number, so that would work too.

+4
source share
1 answer

Like this:

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

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

+6
source

Source: https://habr.com/ru/post/1333436/


All Articles