public void addTextEntry(String textEntry) { var type = AbstractMessage.getMessageType(textEntry); if (type == null) { return; } HashSet <AbstractMessage> messages; if (!dict.TryGetValue(type, out messages)) { return; } AbstractMessage message; try { message = messages .First(m => !m.contains(textEntry)); } catch (Exception ex) { message = new Message1(textEntry); messages.Add(message); return; } message.add(textEntry); }