gpt4 book ai didi

c# - 在 C# 中,从列表中的列表中删除一个元素。

转载 作者:行者123 更新时间:2023-11-30 13:57:06 24 4
gpt4 key购买 nike

我的基本列表包含 ConnectedUser 对象。

List<ConnectedUser> userList = new List<ConnectedUser>();

这是 ConnectedUser 类:

public class ConnectedUser
{
public string phone { get; set; }
public HashSet<string> ConnectionIds { get; set; }
}

那么如何从列表中删除特定的 connectionId??

最佳答案

只需在每个集合中调用 remove 即可。如果集合中没有这样的连接 ID,它不会失败。

string connectionId = "";
foreach (ConnectedUser user in userList)
user.ConnectionIds.Remove(connectionId);

string connectionId = "";
userList.ForEach(u => u.ConnectionIds.Remove(connectionId));

关于c# - 在 C# 中,从列表中的列表中删除一个元素。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22904801/

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