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:

     {
         get
         {
             // connected property will check offlineMode and networkingPeer being null
             if (!connected)
             {
                 return false;
             }

             if (offlineMode)
             {
                 return true;
             }

             switch (connectionStateDetailed)
             {
                 case PeerState.PeerCreated:
                 case PeerState.Disconnected:
                 case PeerState.Disconnecting:
                 case PeerState.Authenticating:
                 case PeerState.ConnectingToGameserver:
                 case PeerState.ConnectingToMasterserver:
                 case PeerState.ConnectingToNameServer:
                 case PeerState.Joining:
                 case PeerState.Leaving:
                     return false; // we are not ready to execute any operations
             }

             return true;
         }
     }