c# - Trying to change color of label through an array which doesn't work? -


I'm trying to create a loop to check if some files exist, and if they do An indicator label on my form, but I do not seem to do this work as to how to type each one manually like this:

  if (File.Exists ( "C: \\ MONEYFILE \\ BOT-PC-8is1.txt")) {PC8IS1.BackColor = Color.Green; } If (file example ("C: \\ monfile \\ BOT-PC-8is2.txt")) {PC8IS2.BackColor = Color.Green; } If (file example ("c: \\ monfile \\ bot-pc-8is3.txt")) {PC8IS3.BackColor = Color.Green; }  

I have tried several basic methods of ordering and substitution, but I can not put "VariableX.backcolor", I have tried [variable]. Backlord, no dice

P> Post-Text "Madprop =" text ">

What you want is a dictionary, the key file name will be, this value will be yours.

  Public Partial Category Form 1 : Form {dictionary & lt; string, label & gt; files; public form 1 () {initialization (); files = new dictionary & lt; string, label & gt; (); Files.Add ("C: \\ Manifest \\ BOT-PC-8is1.txt ", PC8IS1); Files.Add (" C: \\ Monitor \\ BOT-PC-8is2.txt ", PC8IS2); Files.A Dd ("C: \\ monfile \\ BOT-PC-8is3.txt", PC8IS3);} Public Zero Other Func () {foreach (different items in file) {if (File.Exists (item.Key)) item .Value.BackColor = Color.Green;}}}  

Comments