CODEKILLER

반응형

Linq (SelectMany)
Linq (SelectMany)

using System.Xml.Linq;

public class Example
{
    public static void Main()
    {
        Console.Write("<< SelectMany >> \n");
        CodeOwner[] petOwners =
                { new CodeOwner { Name="Code Killer", Codes = new List<string>{ "linq", "foreach" } },
                  new CodeOwner { Name="Code Killer2", Codes = new List<string>{ "string", "int" } },
                  new CodeOwner { Name="Code Killer3", Codes = new List<string>{ "switch", "dowhile" } } };

        // SelectMany로 쿼리.
        IEnumerable<string> query1 = petOwners.SelectMany(codeOwner => codeOwner.Codes);

        Console.WriteLine("Using SelectMany():");

        // 출력.
        foreach (string pet in query1)
        {
            Console.WriteLine(pet);
        }

        Console.WriteLine(System.Environment.NewLine);
        Console.WriteLine("Press any key to exit");
        Console.ReadKey();
    }
}
class CodeOwner
{
    public string Name { get; set; }
    public List<String> Codes { get; set; }
}
반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band