title: foreach statement cannot operate on variables of type 'object'
body: <p>I have 3 dropdownlist 2 with same source, 3rd with selected list. and if selected list not null I should remove selecteds from first one, and bind in 3rd one. second is static that shows orginal list. </p>
  
  <p>but I couldn't figure out how to foreach in an object.</p>
  
  <blockquote>
    <p>ERROR : foreach statement cannot operate on variables of type 'object'
    because 'object' does not contain a public definition for
    'GetEnumerator'</p>
  </blockquote>
  
  <pre><code>    public void DataSource(object source, object select, string Value = "UId", string Text = "Text")
      {
          ddlThis.DataSource = source;
          ddlThis.DataTextField = Text;
          ddlThis.DataValueField = Value;
          ddlThis.DataBind();
  
          ddlThisHidden.DataSource = source;
          ddlThisHidden.DataTextField = Text;
          ddlThisHidden.DataValueField = Value;
          ddlThisHidden.DataBind();
  
          if (select != null)
          {
              ddlOther.DataSource = select;
              ddlOther.DataTextField = Text;
              ddlOther.DataValueField = Value;
              ddlOther.DataBind();
  
              foreach (var item in ddlOther.DataSource)
                  ddlThis.Items.Remove(item);
          }
      }
  </code></pre>
  
  <p>VERSION 2 </p>
  
  <pre><code>    public void DataSource(IList source, IList select, string Value = "UId", string Text = "Text")
      {
          ddlThis.DataSource = source;
          ddlThis.DataTextField = Text;
          ddlThis.DataValueField = Value;
          ddlThis.DataBind();
  
          ddlThisHidden.DataSource = source;
          ddlThisHidden.DataTextField = Text;
          ddlThisHidden.DataValueField = Value;
          ddlThisHidden.DataBind();
  
          if (select != null)
          {
              ddlOther.DataSource = source.Cast&lt;object&gt;()
                  .Select(x =&gt; select.Cast&lt;object&gt;().Any(c=&gt; c.GetType().GetProperty(Value).GetValue(source, null).ToString() == x.GetType().GetProperty(Value).GetValue(source, null).ToString()));
              ddlOther.DataTextField = Text;
              ddlOther.DataValueField = Value;
              ddlOther.DataBind();
  
              foreach (var item in select)
                  ddlThis.Items.Remove(item.ToString());
          }
      }
  </code></pre>
  
  <p>VERSION 3 <strong>WORKING!</strong></p>
  
  <pre><code>    public void DataSource(object source, object select, string Value = "UId", string Text = "Text")
      {
          ddlThis.DataSource = source;
          ddlThis.DataTextField = Text;
          ddlThis.DataValueField = Value;
          ddlThis.DataBind();
  
          ddlThisHidden.DataSource = source;
          ddlThisHidden.DataTextField = Text;
          ddlThisHidden.DataValueField = Value;
          ddlThisHidden.DataBind();
  
          if (select != null)
          {
              ddlOther.DataSource = ((IEnumerable)source).Cast&lt;dynamic&gt;().ToList().FindAll(x =&gt; ((IEnumerable)select).Cast&lt;dynamic&gt;()
                  .Any(c =&gt; c.GetType().GetProperty(Value).GetValue(c, null) == x.GetType().GetProperty(Value).GetValue(x, null)));
  
              ddlOther.DataTextField = Text;
              ddlOther.DataValueField = Value;
              ddlOther.DataBind();
  
              foreach (var item in (dynamic)(ddlOther.DataSource))
                  ddlThis.Items.Remove(item.ToString());
          }
      }
  </code></pre>