Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:50:23+00:00 2026-06-13T09:50:23+00:00

Given a collection IEnumerable<Type> supportedTypes What’s the best way to check whether a given

  • 0

Given a collection

IEnumerable<Type> supportedTypes

What’s the best way to check whether a given object is one of those types (or a derived type)?

My first instinct was to do something like:

// object target is a parameter passed to the method in which I'm doing this.
if (supportedTypes.Count( supportedType => target is supportedType ) > 0)
{
    // Yay my object is of a supported type!!!
}

..but that doesn’t seem to be working. Can I not use the “is” keyword in a lambda expression like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:50:24+00:00Added an answer on June 13, 2026 at 9:50 am

    OK so in the course of typing the question and doing some more experimenting to make sure I wasn’t asking something really stupid, I realized an easy solution. Posting here in case somebody else ever does something equally stupid. 😉

    You can’t use the “is” keyword in your lambda expression, but you can use:

    supportedType => supportedType.IsInstanceOfType(target)
    

    yielding:

    if (supportedTypes.Count( supportedType => 
    supportedType.IsInstanceOfType(target)) > 0)
    

    if (supportedTypes.Any( supportedType => 
                                  supportedType.IsInstanceOfType(target)))
    // object target is a parameter passed to the method in which I'm doing this.
    {
        // Yay my object is of a supported type!!!
    }
    

    hat-tip to Bob Vale for noting in the comments below that I should have been using .Any(…) rather than .Count(…) > 0

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty confused in collection and IEnumerable types. Can any one explain why
According to the answer given for the same question: How to check IEnumerable<DataRow> returns
im getting a CFDictionaryAddValue(): immutable collection 0xd5aea0 given to mutating function error when i
Given: Several million records in a mongo collection. Each record has 10 fields, of
Given a .net 4. collection, if I want to pass in my own custom
Given: <TextBox Text='{Binding MyCollection[MyIndex].MyProperty}'/> where: MyCollection is an observable collection of MyClass items MyClass
Given the following XML structure: <root> <data>x</data> <details> <some_other_element>...</some_other_element> <collection> <element><a>1</a></element> <element><a>2</a></element> <element><a>3</a></element> <collection>
Given the following types public class SomeValue { public int Id { get; set;
When trying to obtain an array of objects from an IEnumerable collection of objects
i have function, which has to accept two types of data - Observable collection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.