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; } }
A Tuple<T1, T2> . " ". KeyValuePair<TKey, TValue> , , - .
Tuple<T1, T2>
KeyValuePair<TKey, TValue>
IComparable IStructuralEquatable, Tuples. , , ?, , .
IComparable
IStructuralEquatable
Tuples, , , , Item1 Item2, .
, Tuple - class (), KeyValuePair - , , , Tuple KeyValuePair ( ref out)
class
KeyValuePair
ref
out
, "" * , . , ( " " ), , :
IEnumerable<Tuple<IWebElement, string>> SelectAllOptions(...)
, , , , , , .
* , CPU, ..
, , .
, , , , , . , .
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.
Source: https://habr.com/ru/post/1538450/More articles:How to control uri in Vaadin using the Navigator - javaLaunch the Windows Phone 8.1 RT app under a locked screen - c #Django user logged out - djangoSignalR Native Host: A connection must be started before data is sent. Call .start () before .send () - signalr не работает - authenticationGetting lasso to work correctly on subplots in matplotlib - pythonHow to call Func without type arguments? - c #ERROR ITMS-9000: "Missing rights to sign the code. Lack of rights to participate in the package" - How to change the application identifier name - iosAndroid - Как использовать локальный вещательный приемник? - androidRunning selenium on a Windows 2008 server - seleniumAll Articles