title: Cannot reach variable outside of for each loop
body: <h2>Im trying to add the variable "email" to the storage queue but cannot reach the variable outside of the for each loop.</h2>
  
  <p>Code works fine if i call "AddMessageToQueue" inside the forloop except that it creates 1000x messages and not one, how can i reach the "email" variable outside of the forloop?</p>
  
  <pre><code> using (var clientContext = new ClientContext(""))
              {
                  clientContext.Credentials = new SharePointOnlineCredentials(userName, result);
  
                  Web web = clientContext.Web;
                  RecycleBinItemCollection rbiColl = web.RecycleBin;
                  clientContext.Load(rbiColl);
  
                  clientContext.ExecuteQuery();
  
                  foreach (RecycleBinItem rbiItem in rbiColl)
                  {
                      log.Info(rbiItem.Title, "ran");
                  }
  
                  log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
  
                  var recyclebinItems = clientContext.Site.GetRecycleBinItems(null, 100, false, RecycleBinOrderBy.DeletedDate, RecycleBinItemState.FirstStageRecycleBin);
                  clientContext.Load(recyclebinItems);
                  clientContext.ExecuteQuery();
                  var items = recyclebinItems.Where(rbi =&gt; rbi.DeletedDate &gt; DateTime.Now.ToUniversalTime().AddMinutes(-10)).ToList();
  
                  for (int i = items.Count() - 1; i &gt;= 0; i--)
                  {
                      var item = items[i];
                      if (item.DirName == "sites/EnfokamTulips/Lists/Tulips")
                      {
                          item.Restore();
                          clientContext.ExecuteQueryRetry();
                          var list = clientContext.Web.GetListByTitle("Tulips");
                          var itemID = item.LeafName.Replace("_.000", "");
                          var listItem = list.GetItemById(itemID);
  
                          clientContext.Load(listItem);
                          clientContext.ExecuteQueryRetry();
  
                          var usr = listItem["TulipOwner"] as FieldUserValue;
                          var email = usr.Email;
                          log.Info(email);
                          listItem.Recycle();
                          clientContext.ExecuteQueryRetry();
  
                      }
                  }
                AddMessageToQueue("tulip", queryString, email);
              }
          }
  
          public static string queryString = ""; ```
  
          public static void AddMessageToQueue(string tulip, string queryString, object email)
          {
              CloudStorageAccount storageAccount = CloudStorageAccount.Parse(queryString);
              CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
              CloudQueue queue = queueClient.GetQueueReference(tulip);
              queue.CreateIfNotExists();
              if (email is string)
              {
                  queue.AddMessage(new CloudQueueMessage((string)email));
              }
              else
              {
                  string message = JsonConvert.SerializeObject(email);
                  queue.AddMessage(new CloudQueueMessage(message));
              }
          }
      }
  }
  </code></pre>