public class Example
{
public static void Main()
{
Console.Write("<< Linq - 필터링 예제 >> \n");
List<CodeStore> markets = new List<CodeStore>
{
new CodeStore { Name = "CK's", Items = new string[] { "kiwi", "cheery", "banana" } },
new CodeStore { Name = "PK's", Items = new string[] { "melon", "mango", "olive" } },
new CodeStore { Name = "ZK's", Items = new string[] { "kiwi", "apple", "orange" } },
};
// items에 특정 문자열이 포함되어 있는 것 찿기.
IEnumerable<string> names = from market in markets
where market.Items.Contains("kiwi")
select market.Name;
foreach (string name in names)
{
Console.WriteLine($"{name} store");
}
Console.WriteLine(System.Environment.NewLine);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
class CodeStore
{
public string Name { get; set; }
public string[] Items { get; set; }
}