title: Cannot implicitly convert anonymous type #1[] to anonymous type #2[]
body: <p>I have following scenario:</p>
  
  <pre><code>public JsonResult ChangeFilterList(int option)
  {
      var data = new[] { new { Text = "Unknown option", Value = -1 } };
      switch (option)
      {
          case 2: data = _departmentnameRepository.All.Select(x =&gt; new { Text = x.DeptName, Value = x.Id }).ToArray();
              break;
          case 3: data = Session["projectid"] == null
                  ? _assetSequenceRepository.All.Select(x =&gt; new { Text = x.AssetShotName, Value = x.Id }).ToArray()
                  : _assetSequenceRepository.FindBy(p =&gt; p.ProjectId == (int)Session["projectid"]).Select(x =&gt; new { Text = x.AssetShotName, Value = x.Id }).ToArray();
              break;
          default: data = _userRepository.All.Select(x =&gt; new { Text = x.DisplayName, Value = x.UserID }).ToArray();
              break;
      }            
  
      return Json(data, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p><code>case2</code> and <code>default</code> looks great but complains on case 3 (conditional) saying: <code>Cannot implicitly convert type 'AnonymousType#1[]' to 'AnonymousType#2[]'</code>. Shouldn't <code>?:</code> be able to decide the type since i already have provided the blueprint for the anonymous as <code>var data = new[] { new { Text = "Unknown option", Value = -1 } };</code>.</p>
  
  <p><strong>Solution:</strong></p>
  
  <p>@Darin Dimitrov answer is great but i want to have some test with anonymous types (Simple cases always need it).
  As @Douglas suspects : My <code>assetSequenceRepository</code> is supplying <code>id</code> as <code>long</code> and anonymous <code>Value</code> goes in favor of <code>int</code> not <code>long</code>. since C# compiler does not implicitly cast <code>long</code> to <code>int</code>, i got the error. Compiling snippet is:</p>
  
  <pre><code>public JsonResult ChangeFilterList(int option = 3)
          {
              var data = new[] { new { Text = "Unknown option", Value = long.MaxValue } };
              switch (option)
              {
                  case 2: data = _departmentnameRepository.All.Select(x =&gt; new { Text = x.DeptName, Value = (long)x.Id }).ToArray();
                      break;
                  case 3: data = Session["projectid"] == null
                          ? _assetSequenceRepository.All.Select(x =&gt; new { Text = x.AssetShotName, Value = x.Id }).ToArray()
                          : _assetSequenceRepository.FindBy(p =&gt; p.ProjectId == (int)Session["projectid"]).Select(x =&gt; new { Text = x.AssetShotName, Value = x.Id }).ToArray();
                      break;
                  default: data = _userRepository.All.Select(x =&gt; new { Text = x.DisplayName, Value = (long)x.UserID }).ToArray();
                      break;
              }            
  
              return Json(data, JsonRequestBehavior.AllowGet);
          }
  </code></pre>