C# 与此功能相反
我有以下代码:C# 与此功能相反,c#,linq,C#,Linq,我有以下代码: private static readonly Dictionary<string, ChatUser> _users = new Dictionary<string, ChatUser>(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary<string, ChatRoom> _rooms = new Dictionary<string, ChatRo
private static readonly Dictionary<string, ChatUser> _users = new Dictionary<string, ChatUser>(StringComparer.OrdinalIgnoreCase);
private static readonly Dictionary<string, ChatRoom> _rooms = new Dictionary<string, ChatRoom>(StringComparer.OrdinalIgnoreCase);
public IEnumerable<ChatUser> GetUsersInRoom(string room)
{
if (String.IsNullOrEmpty(room))
{
return Enumerable.Empty<ChatUser>();
}
var results = from name in _rooms[room].Users
select _users[name];
return results;
}
private static readonly Dictionary\u users=newdictionary(StringComparer.OrdinalIgnoreCase);
私有静态只读字典_rooms=新字典(StringComparer.OrdinalIgnoreCase);
公共IEnumerable GetUsersInRoom(字符串室)
{
if(String.IsNullOrEmpty(房间))
{
返回可枚举的.Empty();
}
var results=来自_rooms[room]中的名称。用户
选择_users[名称];
返回结果;
}
我如何找到不在提供的房间内的人-/ 我试图合并一些反函数,但我似乎无法使它工作。例如?代码示例会有所帮助。
var usersNotInRoom = _users.Values.Except(GetUsersInRoom("ROOM"));