title: How to pass a Global variable into a class in C#
body: <p>I am struggling to find a solution to pass a global variable into a class.</p>
  
  <p>I've tried to create a public function that get the global variable's value it seem like I can't call that function from the class.</p>
  
  <p>Below is my code: </p>
  
  <pre><code>    string latitude = null;
      string longitude = null;
      public string geturl() {
          return  latitude + "," + longitude;
      }
  
      public Form1() {
          Watcher = new GeoCoordinateWatcher();
  
          Watcher.StatusChanged += Watcher_StatusChanged;
          InitializeComponent();
          Watcher.Start();
          ChromiumWebBrowser a = new ChromiumWebBrowser();
          panel1.Controls.Add(a);
          a.Dock = System.Windows.Forms.DockStyle.Fill;
          a.Load("https://drive.google.com/open?id=12j590lCugajX1T64DHKcSiX9RwwBkAeF&amp;usp=sharing");
          CefSettings settings = new CefSettings();
          BrowserLifeSpanHandler blsh = new BrowserLifeSpanHandler();
          a.LifeSpanHandler = blsh;      
      }
  
      public GeoCoordinateWatcher Watcher = null;
  
      private void Watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e) {
          if (e.Status == GeoPositionStatus.Ready){
              // Display the latitude and longitude.
              if (Watcher.Position.Location.IsUnknown){
                  latitude = "Cannot find location data";
              } else {
                  latitude = Watcher.Position.Location.Latitude.ToString();
                  longitude = Watcher.Position.Location.Longitude.ToString();
              }
          }
      }
  
      public class BrowserLifeSpanHandler : ILifeSpanHandler {
          public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName,
              WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo,
              IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) {               
              newBrowser = null;
              MessageBox.Show(targetUrl);
              ChromiumWebBrowser b = new ChromiumWebBrowser(targetUrl);
              return false;
          }
  
          public void OnAfterCreated(IWebBrowser browserControl, IBrowser browser) {
              //
          }
  
          public bool DoClose(IWebBrowser browserControl, IBrowser browser) {
              return false;
          }
  
          public void OnBeforeClose(IWebBrowser browserControl, IBrowser browser) {
              //nothing
          }
      }
  </code></pre>
  
  <p>How can I pass the values of the <code>string geturl()</code> function into the <code>BrowserLifeSpanHandler</code> class?</p>