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

  • SEARCH
  • Home
  • 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 8099165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:18:55+00:00 2026-06-05T22:18:55+00:00

I have a list of parameters like this: public class parameter { public string

  • 0

I have a list of parameters like this:

public class parameter
{
    public string name {get; set;}
    public string paramtype {get; set;}
    public string source {get; set;}
}

IEnumerable<Parameter> parameters;

And a array of strings i want to check it against.

string[] myStrings = new string[] { "one", "two"};

I want to iterate over the parameter list and check if the source property is equal to any of the myStrings array. I can do this with nested foreach’s but i would like to learn how to do it in a nicer way as i have been playing around with linq and like the extension methods on enumerable like where etc so nested foreachs just feel wrong. Is there a more elegant preferred linq/lambda/delegete way to do this.

Thanks

  • 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-05T22:18:56+00:00Added an answer on June 5, 2026 at 10:18 pm

    You could use a nested Any() for this check which is available on any Enumerable:

    bool hasMatch = myStrings.Any(x => parameters.Any(y => y.source == x));
    

    Faster performing on larger collections would be to project parameters to source and then use Intersect which internally uses a HashSet<T> so instead of O(n^2) for the first approach (the equivalent of two nested loops) you can do the check in O(n) :

    bool hasMatch = parameters.Select(x => x.source)
                              .Intersect(myStrings)
                              .Any(); 
    

    Also as a side comment you should capitalize your class names and property names to conform with the C# style guidelines.

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

Sidebar

Related Questions

I have hierarchy: public class Parameter { public string Name { get; set; }
i have code like this public class People { public string name { get;
I have a model public class Foo{ public int Id{get;set;} public string Name {get;
I have a simple object like this public class Test { public string Name
i have a class public with sharing class CAccountRep { string sageAccountNo {get;set;} string
I have the following basic entities: public class Basket { public List<Product> Products {get;set;}
If I have a class like this: public class Foo { public IEnumerable<Bar> Bars
I have a model class like this: namespace Models { public struct Localization {
I have a class that looks like this: public class Analyst { [Column(Internal_ID)] public
I have a method with a parameter containing generics. public static void readList(List<ModelObject> list)

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.