C# 如何在具有哈希表的列表中获取键的值 公共静态列表StoreSearchResult(NgWebDriver驱动程序) { 列表搜索列表=新列表(); Hashtable=新的Hashtable(); //List searchResultList=新列表(); int numberofrows=driver.FindElements(By.XPath(“/*[@id='contenttablegridsearchModal']]/div”).Count; for(int i=0;i

C# 如何在具有哈希表的列表中获取键的值 公共静态列表StoreSearchResult(NgWebDriver驱动程序) { 列表搜索列表=新列表(); Hashtable=新的Hashtable(); //List searchResultList=新列表(); int numberofrows=driver.FindElements(By.XPath(“/*[@id='contenttablegridsearchModal']]/div”).Count; for(int i=0;i,c#,hashtable,C#,Hashtable,我需要用Key.迭代列表中的每个项(它有哈希表) 我正在使用Foreach进行迭代,但我没有获得传递键值的选项 public static List<Hashtable> StoreSearchResult(NgWebDriver driver) { List<Hashtable> searchList = new List<Hashtable>(); Hashtable table = new Hashtable(); // List&

我需要用Key.迭代列表中的每个项(它有哈希表)

我正在使用Foreach进行迭代,但我没有获得传递键值的选项

public static List<Hashtable> StoreSearchResult(NgWebDriver driver)
{
    List<Hashtable> searchList = new List<Hashtable>();
    Hashtable table = new Hashtable();
   // List<SEarchResult> searchResultList = new List<SEarchResult>();
    int numberofrows = driver.FindElements(By.XPath("//*[@id='contenttablegridsearchModal']/div")).Count;

    for (int i = 0; i < numberofrows; i++)
    {
        table.Add("ID",driver.FindElement(By.XPath("//*[@id='row" + i + "gridsearchModal']/div[2]/div")).Text);
        table.Add("Date", driver.FindElement(By.XPath("//*[@id='row" + i + "gridsearchModal']/div[3]/div")).Text);
        table.Add("Type", driver.FindElement(By.XPath("//*[@id='row" + i + "gridsearchModal']/div[4]/div")).Text);
        table.Add("Sub-Type", driver.FindElement(By.XPath("//*[@id='row" + i + "gridsearchModal']/div[5]/div")).Text);
        table.Add("Description", driver.FindElement(By.XPath("//*[@id='row" + i + "gridsearchModal']/div[6]/div")).Text);
        table.Add("Score", driver.FindElement(By.XPath("//*[@id='row" + i + "gridsearchModal']/div[7]/div")).Text);
        table.Add("Asssigned-To", driver.FindElement(By.XPath("//*[@id='row" + i + "gridsearchModal']/div[8]/div")).Text);
        table.Add("Close-Reason", driver.FindElement(By.XPath("//*[@id='row" + i + "gridsearchModal']/div[9]/div")).Text);
    }
    searchList.Add(table);
    int sizeoftable = table.Count;
    int sizeoflist = searchList.Count;
    System.Console.WriteLine(sizeoftable);
    System.Console.WriteLine(searchList);
    return searchList;
}
List searchList=class1.StoreSearchResult(ngdriver);
foreach(搜索列表中的变量项)
{
Hashtable tablevalue=项目;
}

你能帮我吗?

你的意思是循环所有哈希表元素吗?如果是,如下所示:

List<Hashtable> searchList = class1.StoreSearchResult(ngdriver);

foreach (var item in searchList)
{
  Hashtable tablevalue= item;
}
List source=new List();
foreach(源中的哈希表)
{
foreach(hashtable.Keys中的对象键)
{
var值=哈希表[键];
}
}

您的意思是循环所有哈希表元素吗?如果是,如下所示:

List<Hashtable> searchList = class1.StoreSearchResult(ngdriver);

foreach (var item in searchList)
{
  Hashtable tablevalue= item;
}
List source=new List();
foreach(源中的哈希表)
{
foreach(hashtable.Keys中的对象键)
{
var值=哈希表[键];
}
}

它通常类似于
哈希表[key]
。它返回哈希表中的值,您还可以设置值,如
hashtable[key]=value

关于你的例子:

        List<Hashtable> source = new List<Hashtable>();
        foreach (Hashtable hashtable in source)
        {
            foreach (object key in hashtable.Keys)
            {
                var value = hashtable[key];
            }
        }
List searchList=class1.StoreSearchResult(ngdriver);
foreach(搜索列表中的变量项)
{
控制台写入线(项[键]);
}
如果要遍历哈希表,请执行以下操作:

List<Hashtable> searchList = class1.StoreSearchResult(ngdriver);

foreach (var item in searchList)
{
    Console.WriteLine(item[key]);
}
List searchList=class1.StoreSearchResult(ngdriver);
foreach(搜索列表中的变量项)
{
foreach(项目中的var条目){
WriteLine(“{0},{1}”,entry.Key,entry.Value);
}
}

看看。

它通常类似于
哈希表[key]
。它返回哈希表中的值,您还可以设置值,如
hashtable[key]=value

关于你的例子:

        List<Hashtable> source = new List<Hashtable>();
        foreach (Hashtable hashtable in source)
        {
            foreach (object key in hashtable.Keys)
            {
                var value = hashtable[key];
            }
        }
List searchList=class1.StoreSearchResult(ngdriver);
foreach(搜索列表中的变量项)
{
控制台写入线(项[键]);
}
如果要遍历哈希表,请执行以下操作:

List<Hashtable> searchList = class1.StoreSearchResult(ngdriver);

foreach (var item in searchList)
{
    Console.WriteLine(item[key]);
}
List searchList=class1.StoreSearchResult(ngdriver);
foreach(搜索列表中的变量项)
{
foreach(项目中的var条目){
WriteLine(“{0},{1}”,entry.Key,entry.Value);
}
}
看看。

您可以尝试以下方法:

List<Hashtable> searchList = class1.StoreSearchResult(ngdriver);

foreach (var item in searchList)
{
   foreach (var entry in item) {
       Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
   }
}
您可以尝试以下方法:

List<Hashtable> searchList = class1.StoreSearchResult(ngdriver);

foreach (var item in searchList)
{
   foreach (var entry in item) {
       Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
   }
}
使用系统;
使用系统集合;
使用System.Collections.Generic;
命名空间杂技
{
公共静态类启动器
{
公共静态void Main()
{
Hashtable french_numbers=新的Hashtable();
法语字母数字[“零”]=0;
法文字母[“cinq”]=5;
Hashtable english_numbers=新Hashtable();
英语字母数字[“零”]=0;
英文字母数字[“五”]=5;
Console.WriteLine(Launcher.SearchHashTablesByKey)(新列表(){
法国(u)号码,,
英语数字
}("五宗);;
Console.ReadKey(true);
}
私有静态对象SearchHashTablesByKey(列表,对象键)
{
foreach(列表中的哈希表)
{
if(表ContainsKey(键))
{
返回表[键];
}
}
返回null;
}
}
}
使用系统;
使用系统集合;
使用System.Collections.Generic;
命名空间杂技
{
公共静态类启动器
{
公共静态void Main()
{
Hashtable french_numbers=新的Hashtable();
法语字母数字[“零”]=0;
法文字母[“cinq”]=5;
Hashtable english_numbers=新Hashtable();
英语字母数字[“零”]=0;
英文字母数字[“五”]=5;
Console.WriteLine(Launcher.SearchHashTablesByKey)(新列表(){
法国(u)号码,,
英语数字
}("五宗);;
Console.ReadKey(true);
}
私有静态对象SearchHashTablesByKey(列表,对象键)
{
foreach(列表中的哈希表)
{
if(表ContainsKey(键))
{
返回表[键];
}
}
返回null;
}
}
}

我在有多行数据时遇到另一个错误。。System.ArgumentException:已添加项。字典中的键:“ID”正在添加的键:“ID”。。。相反