[Solved] What is the best way to loop through a unknown size string array? [closed]


I will attempt to answer this based off of pulling teeth in the comments, and I’m still not 100% sure if this is even what you are after, but are you after something like this?

Changes

  1. Input parameter is an array so you can actually iterate over it
  2. If statements are properly aligned and not nested

    public void getString(string[] anyString)
    { 
        foreach (var element in anyString.Where(el => !string.IsNullOrEmpty(el)))
        {
            if (element == "item1")
            {
                myOtherMethod(element);
            }
            else if (element == "item2")
            {
                myOtherMethod(element);
            }
            else if (element == "item3")
            {
                myOtherMethod(element);
            }
        }
    }


    public void myOtherMethod(string anyString)
    {
         //do whatever with the string you got.
    }

solved What is the best way to loop through a unknown size string array? [closed]