与此功能相反

时间:2012-04-26 19:16:27

标签: 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, 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;
}

如何在所提供的房间内找到的人? : - /

1 个答案:

答案 0 :(得分:7)

var usersNotInRoom = _users.Values.Except(GetUsersInRoom("ROOM"));