C# Resource Array

2019-01-19 23:19发布

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.

标签: c# resources
1条回答
▲ chillily
2楼-- · 2019-01-20 00:16

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.

查看更多
登录 后发表回答