定义了一个数据字典
private static Dictionary<IWBTcpClient, WBUserInfo> onlineUser = new Dictionary<IWBTcpClient, WBUserInfo>();其中
public class WBUserInfo
{
public string UserName
{
get;
set;
}
public string UserID
{
get;
set;
}
public string GroupID
{
get;
set;
}
}希望把满足foreach (IWBTcpClient client in onlineUser.Keys)
但其中的 onlineUser 只需要满足条件 WBUserInfo 中的GroupID = 1 ,其他的不要表达式如何写,谢谢
private static Dictionary<IWBTcpClient, WBUserInfo> onlineUser = new Dictionary<IWBTcpClient, WBUserInfo>();其中
public class WBUserInfo
{
public string UserName
{
get;
set;
}
public string UserID
{
get;
set;
}
public string GroupID
{
get;
set;
}
}希望把满足foreach (IWBTcpClient client in onlineUser.Keys)
但其中的 onlineUser 只需要满足条件 WBUserInfo 中的GroupID = 1 ,其他的不要表达式如何写,谢谢
foreach (IWBTcpClient client in onlineUser.Keys)
{
if(onlineUser[client].GroupID == 1)
{
list.Add(onlineUser[client]);
}
}
Dictionary<IWBTcpClient, WBUserInfo> groupUser = new Dictionary<IWBTcpClient, WBUserInfo>();
foreach (var user in onlineUser)
{
if(user.Value.GroupID == 1)
groupUser.Add(user.Key, user.Value);
}Dictionary<IWBTcpClient, WBUserInfo> groupUser = new Dictionary<IWBTcpClient, WBUserInfo>();
onlineUser.ToList().ForEach(user =>
{
if (user.Value == "Yfs")
groupUser.Add(user.Key, user.Value);
}
);