public static void SendBatch(IRCConnection conn, IChannel channel, IEnumerable <IUser> users) { const int max_length = 400; // allow for 112 characters of overhead int length = 0; List <string> userNames = new List <string>(); void sendBatch() { if (length < 1) { return; } conn.SendReply(new NamesReply(channel, userNames)); length = 0; userNames.Clear(); }; foreach (IUser user in users) { string name = user.GetIRCName(channel); int nameLength = name.Length + 1; if (length + nameLength > max_length) { sendBatch(); } length += nameLength; userNames.Add(name); } sendBatch(); }