将列表传递给 RootElement c# 中的部分
Pass list to Section within RootElement c#
我正在向 RootElement 的一部分添加某些值,如下所示:-
NavigationRoot = new RootElement("Menu"){ //Here we create the root of the elements
new Section("Pages"){
new StringElement ("Feed"),
new StringElement ("Messages"),
new StringElement ("Nearby"),
new StringElement ("Events"),
new StringElement ("Friends"),
},
现在,StringElements 是硬编码的。我想将我从 API 调用中获取的字符串列表传递给该部分。该列表将是动态的。如何传递此列表以创建具有列表中字符串值的项目部分?
感谢任何帮助。
var section = new Section("Pages");
foreach(var s in MyListOfStrings) {
section.Add(new StringElement(s));
}
如果你有一个字符串数组,你可以使用 Linq 试试这个:-
from page in myStringArray select new StringElement (page) as Element;
我正在向 RootElement 的一部分添加某些值,如下所示:-
NavigationRoot = new RootElement("Menu"){ //Here we create the root of the elements
new Section("Pages"){
new StringElement ("Feed"),
new StringElement ("Messages"),
new StringElement ("Nearby"),
new StringElement ("Events"),
new StringElement ("Friends"),
},
现在,StringElements 是硬编码的。我想将我从 API 调用中获取的字符串列表传递给该部分。该列表将是动态的。如何传递此列表以创建具有列表中字符串值的项目部分?
感谢任何帮助。
var section = new Section("Pages");
foreach(var s in MyListOfStrings) {
section.Add(new StringElement(s));
}
如果你有一个字符串数组,你可以使用 Linq 试试这个:-
from page in myStringArray select new StringElement (page) as Element;