John Riker

John Riker

  • NA
  • 85
  • 16k

Array, loop, what # am I on?

Mar 12 2021 1:37 PM
I am trying to avoid another variable counting where I'm at in a loop, but need to find out something and trying to find a work around.
 
So here's the deal.  I have a comma separated list of values in a  config file.  Read in the values like this:
 
string[] JSONShowUrls = ConfigurationManager.AppSettings["jsonshowurls"].Split(',').Select(s => s.Trim()).ToArray(); 
 
So I  loop thru those 
  1. foreach (string showsurls in JSONShowUrls)   
  2.   {  
  3.      if (rootObject.tiles != null// Check if the show returned any data   
  4.        {  
  5.          do something  
  6.        }  
  7.       else  
  8.         {  
  9.            write no data  
  10.          }   
  11.   }   
 Now here's the problem I'm trying to solve.  On the part that says "write no data".  I am currently outputting that no shows were found but not what show it is.  Not a big deal but still nice to see.  So I have this:
 
string[] JSONShowNames = ConfigurationManager.AppSettings["jsonshownames"].Split(',').Select(s => s.Trim()).ToArray(); 
 
So this has a list of the names of each show in case it's needed.  It's in the same order as the prior config value.  So in theory whatever # in the loop
  1. foreach (string showsurls in JSONShowUrls)
is,  the name of the show would be in that same spot in JSONShowNames above.  Any way to easily pull the right array number off JSONShowNames  if the current array of JSONShowUrls is empty?
 
Hope this makes some sense.
 
Thanks.
 
JR 

Answers (1)