title: c# little stuck on getting return
body: <p>normally I learn by finding example of what I need and reverse engineer it but I'm stuck on this one,
  goal is to get IP and NAME back and put it in array to use later to create buttons to manage host or pull network details (if switch or ruter)...
  how can I get the active IP's and names from the ping section?
  here's what I have so far...:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Net.NetworkInformation;
  using System.Diagnostics;
  using System.Net;
  using System.Threading;
  using System.Net.Sockets;
  using Control;
  using System.Dynamic;
  
  namespace ConsoleApplication1
  {
  class Program
  {
      static CountdownEvent countdown;
      static int upCount = 0;
      static object lockObj = new object();
      const bool resolveNames = true;
  
      static void Main(string[] args)
      {
          countdown = new CountdownEvent(1);
          Stopwatch sw = new Stopwatch();
          sw.Start();
          var K = LocalIP .GetLocalIPAddress();
          string[] ipParts = K.Split('.');
  
          string l = ipParts[1];
          int n = 0;
          Int32.TryParse(l, out n);
          Console.WriteLine(n);
          if (n &lt; 200)
          {
              string ipBase = ipParts[0] + "." + ipParts[1] + ".";
              for (int i = 0; i &lt; 255; i++)
              {
                  string ippart = ipBase + i + ".";
                  for (int j = 1; j &lt; 255; j++)
                  {
                      var ip = ippart + j;
                      Ping p = new Ping();
                      p.PingCompleted += new PingCompletedEventHandler(p_PingCompleted);
                      countdown.AddCount();
                      p.SendAsync(ip, 100, ip);
                      string k = resolveNames.ToString();
  
                      if (k.Contains(ipBase))
                      {
                          Console.WriteLine($"{k} working");
                      }
                      else
                      {
  
                      }
                  }
              }
  
          countdown.Signal();
          countdown.Wait();
          sw.Stop();
          TimeSpan span = new TimeSpan(sw.ElapsedTicks);
          Console.WriteLine("Took {0} milliseconds. {1} hosts active.", sw.ElapsedMilliseconds, 
  upCount);
  
          }
          else
          {
              Console.WriteLine("Corporate Network detected");
          }
      }
  
  
      static void p_PingCompleted(object sender, PingCompletedEventArgs e )
      {
          string ip = (string)e.UserState;
          if (e.Reply != null &amp;&amp; e.Reply.Status == IPStatus.Success)
          {
              if (resolveNames)
              {
  
                  string name;
                  try
                  {
                      IPHostEntry hostEntry = Dns.GetHostEntry(ip);
                      name = hostEntry.HostName;
                  }
                  catch (SocketException ex)
                  {
                     name = "?";
                  }
  
                  Console.WriteLine("{0} ({1}) is up: ({2} ms)", ip, name, e.Reply.RoundtripTime);
                      }
              else
              {
                //  Console.WriteLine("{0} is up: ({1} ms)", ip, e.Reply.RoundtripTime);
              }
  
          } 
          countdown.Signal();
  
      }
  }
  }
  </code></pre>
  
  <p>if current code is run i do get console output:</p>
  
  <pre><code>168
  192.168.0.29 (PCname.Home) is up: (0 ms)
  192.168.136.1 (PCname.mshome.net) is up: (0 ms)
  192.168.0.1 (nowtvhub.Home) is up: (3 ms)
  Took 27459 milliseconds. 0 hosts active.
  </code></pre>
  
  <p>but cannot figure out how to put it in to array...</p>
  
  <p>Cheers for advise, now did this, Does that look right?</p>
  
  <pre><code>            List&lt;IPandHostStore&gt; AllIPandHostStore = new List&lt;IPandHostStore&gt;();
  
          string ip = (string)e.UserState;
          if (e.Reply != null &amp;&amp; e.Reply.Status == IPStatus.Success)
          {
              if (resolveNames)
              {
  
                  string name;
                  try
                  {
                      IPHostEntry hostEntry = Dns.GetHostEntry(ip);
                      name = hostEntry.HostName;
                  }
                  catch (SocketException ex)
                  {
                      name = "?";
                  }
  
                  // var temp = string.Format("{0},{1})", ip, name);
                  AllIPandHostStore.Add(new IPandHostStore { ip = ip, name = name, });
  
                   Console.WriteLine("{0} ({1}) is up: ({2} ms)", ip, name, e.Reply.RoundtripTime);
  </code></pre>
  
  <p>and class list..</p>
  
  <pre><code>namespace Control
  {
  public class IPandHostStore
  {
  
      public string name { set; get; }
      public string ip { set; get; }
  
      public void AllIPandHostStore(string ip, string name)
      {
          this.name = name;
          this.ip = ip;
  
      }
  }
  }
  </code></pre>
  
  <p>how can I pull the list in Main... ?</p>