title: PowerShell Converting $null into 0
body: <p>I have a pretty straight-forward function for grabbing SQL results: </p>
  
  <pre><code>function RunSqlCommand($sql)
  {
      $connection = $null
      $command = $null
      try
      {
          $connectionString = "data source=localhost; integrated security=true"
          $connection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
          $command = $connection.CreateCommand()
          $command.CommandText = $sql
          $adapter = New-Object System.Data.SqlClient.SqlDataAdapter($command)
          $dataSet = New-Object System.Data.DataSet
          $adapter.Fill($dataSet)
          $results = $dataSet.Tables | Select-Object -ExpandProperty "Rows"
          return $results
      }
      finally
      {
          if ($command -ne $null) { $command.Dispose() }
          if ($connection -ne $null) { $connection.Dispose() }
      }
  }
  </code></pre>
  
  <p>Whenever there are no results, the <code>$results</code> variable is <code>$null</code>. However, when I inspect the return value in the calling method, it magically becomes <code>0</code>.</p>
  
  <p>Is PowerShell doing something behind the scenes? I really do want to return <code>$null</code> to represent "no results".</p>