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 GuiSendsMsg()
     {
         if (string.IsNullOrEmpty(this.inputLine))
         {

             GUI.FocusControl("");
             return;
         }

         if (this.inputLine[0].Equals('\\'))
         {
             string[] tokens = this.inputLine.Split(new char[] {' '}, 2);
             if (tokens[0].Equals("\\help"))
             {
                 this.PostHelpToCurrentChannel();
             }
             if (tokens[0].Equals("\\state"))
             {
                 int newState = int.Parse(tokens[1]);
                 this.chatClient.SetOnlineStatus(newState, new string[] { "i am state " + newState }); // this is how you set your own state and (any) message
             }
             else if (tokens[0].Equals("\\subscribe") && !string.IsNullOrEmpty(tokens[1]))
             {
                 this.chatClient.Subscribe(tokens[1].Split(new char[] {' ', ','}));
             }
             else if (tokens[0].Equals("\\unsubscribe") && !string.IsNullOrEmpty(tokens[1]))
             {
                 this.chatClient.Unsubscribe(tokens[1].Split(new char[] {' ', ','}));
             }
             else if (tokens[0].Equals("\\clear"))
             {
                 if (this.doingPrivateChat)
                 {
                     this.chatClient.PrivateChannels.Remove(this.selectedChannelName);
                 }
                 else
                 {
                     ChatChannel channel;
                     if (this.chatClient.TryGetChannel(this.selectedChannelName, this.doingPrivateChat, out channel))
                     {
                         channel.ClearMessages();
                     }
                 }
             }
             else if (tokens[0].Equals("\\msg") && !string.IsNullOrEmpty(tokens[1]))
             {
                 string[] subtokens = tokens[1].Split(new char[] {' ', ','}, 2);
                 string targetUser = subtokens[0];
                 string message = subtokens[1];
                 this.chatClient.SendPrivateMessage(targetUser, message);
             }
         }
         else
         {
             if (this.doingPrivateChat)
             {
                 this.chatClient.SendPrivateMessage(this.userIdInput, this.inputLine);
             }
             else
             {
                 this.chatClient.PublishMessage(this.selectedChannelName, this.inputLine);
             }
         }

         this.inputLine = "";
         GUI.FocusControl("");
     }