public virtual void Send(string from, string to, string message) { // using dict's key as receiver, no need for actual value/object IParticipant participant = Participants[to]; // checking if participant excists, needed because sender may not have correct key if (participant != null) { participant.Receive(from, message); } }
public void Send(string from, string to, string message) { IParticipant target = participants[to]; if (target != null) { target.Receive(from, message); } else { throw new Exception("Invalid chat participant!"); } }
public void Send(string from, string to, string message) { Console.WriteLine($"Chatroom got message: {message}. From: {from}. To: {to}"); if (to.ToLower() == "all") { foreach (var pair in participants) { if (pair.Value.Name != from) { pair.Value.Receive(from, message); } } } else { IParticipant receiver = participants[to]; if (receiver != null) { receiver.Receive(from, message); } } }