gpt4 book ai didi

c# - 如何将列表添加到列表中?

转载 作者:行者123 更新时间:2023-11-30 15:25:18 24 4
gpt4 key购买 nike

好的,我有这个:

if(something!=null)
{
SubMenu.Add(new SubMenuModel("PERSONAL_INFORMATION","account.personalinformation","/account/personalinformation"));
}
if(something123!=null)
{
SubMenu.Add(new SubMenuModel("NOTIFICATIONS", "account.notificationsettings", "/account/notifications"));
}
SubMenu.Add(new SubMenuModel("CHANGE_PASSWORD", "account.changepassword", "/account/passwordchange"));
SubMenu.Add(new SubMenuModel("GAME_SETTINGS", "default", "default"));

MainMenu.Add(new MainMenuModel("SETTINGS", "default", "default", true,




}));

编辑:

public List<SubMenuModel> SubMenu { get; set; } 
public List<MainMenuModel> MainMenu { get; set; }

我如何将此 SubMenu 添加到 Main menu 中,因为我有条件,所以如果条件为 !=null 添加到列表...有任何建议吗?

最佳答案

可以关注这个link .

你只需要做 MainMenu.AddRange(SubMenu);

希望对你有帮助

编辑:好的,所以你可以做到这一点我认为你可以将 MenuItems 添加到现有的 MenuItem 中,例如:

MenuItem addDevice = new MenuItem("Add Device");
addDevice.MenuItems.Add( new MenuItem("Add More .."));
It would be visible like:

submenu

我看到了这个解决方案 here它对我有用。

关于c# - 如何将列表添加到列表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31449512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com