Учитывая приведенный ниже код, я хочу иметь возможность найти элемент в myProjectsDicList
, используя ключ (строку) в другом словаре. Но ищите его в массиве projectsArrayList
. В частности, строка htmleditor.ProjectName
- это то, что я хочу найти. В словаре только 1 List<ArrayList>
. Этот список массивов содержит список массивов проектов.
Я попробовал это ниже, но не работает ....
string key = "Project Name";
var match = myProjectsDicList.Where(item => item.Value[0].Cast<object>().Where(x => x.ProjectName == key).Select(x => x.ProjectName).First());
Я пытаюсь найти способ заменить этот код на найдите HTMLEditor, который работает с оператором select.
bool foundHTMLEditor = false;
for (int i = 0; i < myProjectsDicList.Count; i++)
{
List<ArrayList> allprojects = myProjectsDicList.ElementAt(i).Value;
for (int j = 0; j < allprojects[0].Count; j++)
{
HTMLEditor e = (HTMLEditor)allprojects[0][j];
if (e.ProjectName == key)
{
foundHTMLEditor = true;
break;
}
}
if(foundHTMLEditor == true)
{
break;
}
}
Вот код, который у меня есть ...
public class MultiDimDictList : Dictionary<string, List<ArrayList>>
{
}
projects = new ArrayList();
List<ArrayList> projectsArrayList = new List<ArrayList>();
// create the dictionary
MultiDimDictList myProjectsDicList = new MultiDimDictList();
// create an htmleditor instance and set one of the variables
HTMLEditor htmleditor = new HTMLEditor();
htmleditor.ProjectName = "Project Name";
// add the htmleditor to the projects array list
projects.Add(htmleditor);
// add the projects array list to the List
projectsArrayList.Add(projects);
// add the projects array list to the dictionary list
myProjectsDicList.Add(domainName, projectsArrayList);