mardi 28 septembre 2021

A function that change a Collection to an array

I am practicing selenium and web elements. I want to write a function that gets any collection and change return it as an array.

// Here I catch some tipe of collection - (System.Collections.ObjectModel.ReadOnlyCollection<OpenQA.Selenium.IWebElement>)

    public System.Collections.ObjectModel.ReadOnlyCollection<OpenQA.Selenium.IWebElement> Focus_Side_Bar_List()
    {
        WebWaitElementExist.ByCssSelector(Driver, "[data-menu-id='1']");
        return Driver.FindElements(By.CssSelector("[data-menu-id='1']>li"));
    }

This is what i am wishing to have a generic function can makes any collection to an array:

    public string[] Collection_To_Array(Collection<T> AnyCollection)
    {
        var NewArray = new string[AnyCollection.length];
        for (int i = 0; i < AnyCollection.length; i++)
        {
            NewArray[i] = AnyCollection[i].Text;
        }
        return NewArray;
    }



Aucun commentaire:

Enregistrer un commentaire