title: Visual C# check type of array elements with lambda expression
body: <p>I have an array that contains various type of elements.</p>
  
  <p>I am trying to construct a lambda expression that will evaluate the if clause true if a specific type exists in the array.</p>
  
  <p>I was trying the following and many different approaches but I don't seem to get it right:</p>
  
  <pre class="lang-cs prettyprint-override"><code>var arraySourceText = EditorController.ActiveDocument
                                        .ActiveSegmentPair
                                        .Source
                                        .AllSubItems
                                        .ToArray();
  
  if (arraySourceText.Any(o =&gt; o.GetType()) == typeof(string))
  {
     intStartingPH++;
  }
  </code></pre>
  
  <p>Any advice is welcome.</p>
  
  <p>Note: the <code>arraySourceText</code> is an API <code>IEnumerable</code> with custom types. I just assumed <code>string</code> for simplicity in the pseudocode.</p>
  
  <p><em>Update:</em> Because the type is not exposed by the API, only the name of the type, the workaround was based on Byyo's correction. I wrote a separate method to check the name of the type and return a <code>bool</code>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>var arraySourceText = EditorController.ActiveDocument
                                        .ActiveSegmentPair
                                        .Source
                                        .AllSubItems
                                        .ToArray();
  
  string typePH = "PlaceholderTag";
  
  if (arraySourceText.Any(o =&gt; IsMatchTypeString(typePH, o)))
      {
          intStartingPH++;
      }
  
  //Then the below method does the check:
  
  static bool IsMatchTypeString(string testtype, params object[] items)
  {
      if (items.Length == 0)
      {
          return false;
      }
      else if (testtype == items[0].GetType().ToString())
      {
          return true;
      }
      else
      {
          return false;
      }
  }
  </code></pre>