Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

         private void HandlePrivateMessageEvent(EventData eventData)
         {
             //Console.WriteLine(SupportClass.DictionaryToString(eventData.Parameters));

             var message = (object)eventData.Parameters[(byte)ChatParameterCode.Message];
             var sender = (string)eventData.Parameters[(byte)ChatParameterCode.Sender];

             string channelName;
             if (this.UserId != null && this.UserId.Equals(sender))
             {
                 var target = (string)eventData.Parameters[(byte)ChatParameterCode.UserId];
                 channelName = this.GetPrivateChannelNameByUser(target);
             }
             else
             {
                 channelName = this.GetPrivateChannelNameByUser(sender);
             }

             ChatChannel channel;
             if (!this.PrivateChannels.TryGetValue(channelName, out channel))
             {
                 channel = new ChatChannel(channelName);
                 channel.IsPrivate = true;
                 this.PrivateChannels.Add(channel.Name, channel);
             }

             channel.Add(sender, message);
             this.listener.OnPrivateMessage(sender, message, channelName);
         }