Answer the question
In order to leave comments, you need to log in
How to access resources dynamically (by index or otherwise)?
There is a code in which, depending on the condition, one or another audio file (.wav) should be launched. Also included are 46 .wav files as resources that can be accessed via:
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
///...
player.Stream = Properties.Resources.a; // a -- audio file
Answer the question
In order to leave comments, you need to log in
Properties.Resources.ResourceManager
See the GetObject and GetStream methods, you can refer to a resource by name
Design patterns have been invented for such tasks. Of course 46 if else if is evil. In my opinion, a state-machine may come in handy here, although it’s not very important. The bottom line is - You will make 46 classes that implement the same GetStream method (name for example), and in the code you will replace the class with user actions. Something like
someObject.State = new WarningState()
player.Stream = someObject.State.GetStream();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question