© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
35 replies
malkav

❔ Using two lists, compare, and render based on smaller list [Answered]

So I've got two List items, and I need to render one list, and make "green" based on the value in the second list.
Example:
List<string> renderItems = new();
List<MatchingItem> compareItems = new();

public class MatchingItem
{
  public string Name {get;set;}
  public bool Matches {get;set;}
}
List<string> renderItems = new();
List<MatchingItem> compareItems = new();

public class MatchingItem
{
  public string Name {get;set;}
  public bool Matches {get;set;}
}


Say I have 7 items in the list
renderItems
renderItems
and I've got 47 in the list
compareItems
compareItems
of which maybe three items have the field
Matches
Matches
set to true.

So I need to render the 7 items of
renderItems
renderItems
with a text-color of grey, but for those three items that have both the field
Name
Name
equal to the string in
renderItems
renderItems
and the field
Matches
Matches
set to true, I want the text-color set to green.

Now I've been trying with foreach in foreach and such, but I'm getting a bit confused and lost. Please halp

Here's what I've tried:
public void AttemptMethod()
{
  foreach (var item in renderItems)
  {
    foreach (var comp in compareItems)
    {
      if (comp.Name == item && comp.Matches)
      {
        // render green?
      } 
      else
      {
        // render grey??
      }
    }
  }
}
public void AttemptMethod()
{
  foreach (var item in renderItems)
  {
    foreach (var comp in compareItems)
    {
      if (comp.Name == item && comp.Matches)
      {
        // render green?
      } 
      else
      {
        // render grey??
      }
    }
  }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ compare two dates
C#CC# / help
4y ago
❔ Foreach on two different lists
C#CC# / help
3y ago