using System.Collections.Generic;
public static void Main()
List<string> tagsIncl = new List<string> { "TestServer", "TBAPPL10", "Tbappl08" };
List<string> tagsExcl = new List<string> { "APPOLB" };
List<Agent> agents = new List<Agent>()
new Agent { Name = "TBAPPL10", Environment = "Test", Tags=new List<string>()
"BusinessCritical","TestServer","Tbappl10","APPEOS"
new Agent { Name = "TBAPPL08", Environment = "Test", Tags=new List<string>()
"BusinessCritical","TestServer","Tbappl08","APPOLB"
new Agent { Name = "ABAPPL10", Environment = "Accept", Tags=new List<string>()
"BusinessCritical","AcceptServer","Tbappl10","APPEOS"
new Agent { Name = "ABAPPL08", Environment = "Accept", Tags=new List<string>()
"BusinessCritical","AcceptServer","Abappl08","APPOLB"
HashSet<string> agentsList = new HashSet<string>();
foreach (Agent agent in agents)
if (!agent.Environment.Equals(env)) continue;
foreach (string ti in tagsIncl)
if(agent.Tags.Contains(ti, StringComparer.OrdinalIgnoreCase)) agentsList.Add(agent.Name);
foreach (string te in tagsExcl)
if (agent.Tags.Contains(te, StringComparer.OrdinalIgnoreCase)) agentsList.Remove(agent.Name);
foreach (string agent in agentsList){
Console.WriteLine("Selected agent: "+agent);
public string Name { set; get; }
public string Environment { set; get; }
public List<string> Tags { set; get; }