What is the advantage of using two subjects over a dictionary?

I have a code where I return a list of IWebElements and their respective names? I understand that a tuple with two elements is basically the same thing, but the dictionary uses a hash mapping to bind the two values. What is the advantage of using a two-position tuple over a dictionary or vice versa?

public Dictionary<IWebElement, string> SelectAllOptions(IWebDriver driver, ref DataObject masterData)
    {
        //Get the ID of the dropdown menu
        DatabaseRetrieval.GetObjectRepository(ref masterData);
        var strDropMenuId = masterData.DictObjectRepository["ID"];
        //Find the dropdown menu and pull all options into a list
        try
        {
            var dropMenu = new SelectElement(driver.FindElement(By.Id(strDropMenuId)));
            // TODO want to know how we want this list to return. 
            var options = dropMenu.Options as List<IWebElement>;
            if (options != null)
            {
                var values = options.ToDictionary(option => option, option => option.Text);
                return values;
            }
        }
+4
source share
3 answers

A Tuple<T1, T2> . " ". KeyValuePair<TKey, TValue> , , - .

IComparable IStructuralEquatable, Tuples. , , ?, , .

Tuples, , , , Item1 Item2, .

, Tuple - class (), KeyValuePair - , , , Tuple KeyValuePair ( ref out)

+9

, "" * , . , ( " " ), , :

IEnumerable<Tuple<IWebElement, string>> SelectAllOptions(...)
  • , -
  • , - .
  • , .

, , , , , , .

* , CPU, ..

+9

, , .

, , , , , . , .

Another advantage is that you can put as many pairs with the same first element in the list as you want, where with the dictionary you can have only one value for each unique key.

+1
source

Source: https://habr.com/ru/post/1538450/


All Articles