title: Parsing an array of objects in C#
body: <p>I have an array of objects and I would like to pass it into a method that only accepts <code>DOUBLE</code>, <code>NULL</code>, <code>STRING</code> or <code>DATETIME</code>. So when I try to pass in the value it gives an error saying I can't pass in any arbitrary object and that it has to be parsed as a <code>DOUBLE</code>, <code>NULL</code>, <code>STRING</code> or <code>DATETIME</code> first.</p>
  
  <pre><code>foreach (var currRow in dataSet.Tables[0].Rows)
  {
      var tuple = Com.Tibco.As.Space.Tuple.Create();
  
      //here is where i loop through the object array
      for (int i = 0; i &lt; currRow.Values.Length; i++)
      {
          //here is where i try to pass it to the method (which doesn't accept it)
          tuple.Put(dataSet.Tables[0].ColumnNames[i], currRow.Values[i]);
      }
  
      inSpace_.Put(tuple);
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/dlwl0.png" alt="Heres what the array of objects look like"></p>
  
  <p>In short I need a way to parse each object and cast it as the appropriate one and then put it inside the tuple.</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Here's what I tried to do, but it didn't work:</p>
  
  <pre><code>foreach (var currRow in dataSet.Tables[0].Rows)
  {
      var tuple = Com.Tibco.As.Space.Tuple.Create();
  
      for (int i = 0; i &lt; currRow.Values.Length; i++)
      {
          if (currRow.Values[i] != null)
          {
              if (dataSet.Tables[0].ColumnNames[i].GetType().IsEquivalentTo(typeof(DateTime)))
              {
                  DateTime value = DateTime.Parse(dataSet.Tables[0].ColumnNames[i].ToString());
                  tuple.Put(dataSet.Tables[0].ColumnNames[i], value);
              }
              else if (dataSet.Tables[0].ColumnNames[i].GetType().IsEquivalentTo(typeof(Double)))
              {
                  Double value = Convert.ToDouble(dataSet.Tables[0].ColumnNames[i]);
                  tuple.Put(dataSet.Tables[0].ColumnNames[i], value);
              }
              else
              {
                  string value = dataSet.Tables[0].ColumnNames[i].ToString();
                  tuple.Put(dataSet.Tables[0].ColumnNames[i], value);
              }
          }
      }
      inSpace_.Put(tuple);
  }
  </code></pre>