title: How to segregate double and string items, getting invalid cast error
body: <p>I have a <code>Dictionary&lt;string, object&gt;</code> which has <code>string</code> and <code>double</code> value for <code>object</code>. Now I want to segregate both value type in below code. Currently I am getting <strong>invalid cast error</strong>. How to do this?</p>
  
  <pre><code>namespace ConsoleApp26
  {
  public class Sample
  {
      public string SampleName;
      public Dictionary&lt;string, object&gt; SampleValues;
  }
  
  public class SampleDivideBetweenDoubleAndStringValue
  {
      public string Name { get; set; }
      public double DoubleValue { get; set; }
      public string StringValue { get; set; }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          try
          {
              var samples = new Sample
              {
                  SampleName = "test",
                  SampleValues = new Dictionary&lt;string, object&gt; { 
                      { "t1",  45.08 }, 
                      { "t2", "A String Value" }, 
                      { "t3",  83 } 
                  }
              };
  
              var tuple = GetTuple(samples);
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
  
          Console.ReadKey();
      }
  
      private static Tuple&lt;IEnumerable&lt;SampleDivideBetweenDoubleAndStringValue&gt;, IEnumerable&lt;SampleDivideBetweenDoubleAndStringValue&gt;&gt; GetTuple(Sample samples)
      {
          var doubles = (from s in samples.SampleValues
                         select new SampleDivideBetweenDoubleAndStringValue
                         {
                             Name = samples.SampleName,
                             DoubleValue = (double)s.Value
                         });
  
          var strings = (from s in samples.SampleValues
                         select new SampleDivideBetweenDoubleAndStringValue
                         {
                             Name = samples.SampleName,
                             StringValue = (string)s.Value
                         });
  
          return new Tuple&lt;
            IEnumerable&lt;SampleDivideBetweenDoubleAndStringValue&gt;, 
            IEnumerable&lt;SampleDivideBetweenDoubleAndStringValue&gt;&gt;(doubles, strings);
      }
  }
  }
  </code></pre>