title: Using ManagementObject to retrieve a single WMI property
body: <p>This probably isn't the best way, but I am currently retrieving the amount of RAM on a machine using:</p>
  
  <pre><code>manageObjSearch.Query = new ObjectQuery("SELECT TotalVisibleMemorySize FROM Win32_OperatingSystem");
  manageObjCol = manageObjSearch.Get();
  
  foreach (ManagementObject mo in manageObjCol)
   sizeInKilobytes = Convert.ToInt64(mo["TotalVisibleMemorySize"]);</code></pre>
  
  <p>It works well and good, but I feel I could be doing this more directly and without a foreach over a single element, but I can't figure out how to index a <code>ManagementObjectCollection</code></p>
  
  <p>I <em>want</em> to do something like this:</p>
  
  <pre><code>ManagementObject mo = new ManagementObject("Win32_OperatingSystem.TotalVisibleMemorySize")
  mo.Get();
  
  Console.WriteLine(mo["TotalVisibleMemorySize"].ToString())</code></pre>
  
  <p>or maybe even something like</p>
  
  <pre><code>ManagementClass mc = new ManagementClass("Win32_OperatingSystem");
  Console.WriteLine(mc.GetPropertyValue("TotalVisibleMemorySize").ToString());</code></pre>
  
  <p>I just can't seem to figure it out.  Any ideas?</p>