Avatar of Scarlett72
Scarlett72

asked on 

How to use string.join in method

I'm trying to create a method that returns a comma separated list of all Calendar controls on a page, the solutions I've read have suggested using string.join; however, I an confused on how to implement this.  Could this also be an alternative solution?

protected String GetAllCalControls()
    {
        StringBuilder countCal = new StringBuilder();            
        foreach (Control ctrl in Page.Controls)
        {
            foreach (Control childc in ctrl.Controls)
            {
                if (childc is Calendar)
                {
                    countCal.Append(childc.ID+",");
                }
            }
        }
        countCal.Remove(countCal.Length, -1);
        return countCal.ToString();
    }

Open in new window

C#ASP.NET

Avatar of undefined
Last Comment
Scarlett72

8/22/2022 - Mon