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:

     public void SetReceivingEnabled(int[] enableGroups, int[] disableGroups)
     {
         List enableList = new List();
         List disableList = new List();

         if (enableGroups != null)
         {
             for (int index = 0; index < enableGroups.Length; index++)
             {
                 int i = enableGroups[index];
                 if (i <= 0)
                 {
                     Debug.LogError("Error: PhotonNetwork.SetReceivingEnabled was called with an illegal group number: " + i + ". The group number should be at least 1.");
                     continue;
                 }
                 if (!this.allowedReceivingGroups.Contains(i))
                 {
                     this.allowedReceivingGroups.Add(i);
                     enableList.Add((byte)i);
                 }
             }
         }
         if (disableGroups != null)
         {
             for (int index = 0; index < disableGroups.Length; index++)
             {
                 int i = disableGroups[index];
                 if (i <= 0)
                 {
                     Debug.LogError("Error: PhotonNetwork.SetReceivingEnabled was called with an illegal group number: " + i + ". The group number should be at least 1.");
                     continue;
                 }
                 if (enableList.Contains((byte)i))
                 {
                     Debug.LogError("Error: PhotonNetwork.SetReceivingEnabled disableGroups contains a group that is also in the enableGroups: " + i + ".");
                     continue;
                 }
                 if (this.allowedReceivingGroups.Contains(i))
                 {
                     this.allowedReceivingGroups.Remove(i);
                     disableList.Add((byte)i);
                 }
             }
         }

         this.OpChangeGroups(disableList.Count > 0 ? disableList.ToArray() : null, enableList.Count > 0 ? enableList.ToArray() : null); //Passing a 0 sized array != passing null
     }