C#C
C#4y ago
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;}
}


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

So I need to render the 7 items of renderItems with a text-color of grey, but for those three items that have both the field Name equal to the string in renderItems and the field 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??
      }
    }
  }
}
Was this page helpful?