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 ParseResult(string result)
     {
         if (string.IsNullOrEmpty(result))
         {
             this.Message = "Server's response was empty. Please register through account website during this service interruption.";
             return;
         }

         Dictionary values = JsonConvert.DeserializeObject>(result);
         if (values == null)
         {
             this.Message = "Service temporarily unavailable. Please register through account website.";
             return;
         }

         int returnCodeInt = -1;
         string returnCodeString = string.Empty;
         string message;

         values.TryGetValue("ReturnCode", out returnCodeString);
         values.TryGetValue("Message", out message);
         int.TryParse(returnCodeString, out returnCodeInt);

         this.ReturnCode = returnCodeInt;
         if (returnCodeInt == 0)
         {
             // returnCode == 0 means: all ok. message is new AppId
             this.AppId = message;
         }
         else
         {
             // any error gives returnCode != 0
             this.AppId = string.Empty;
             this.Message = message;
         }
     }