다음을 통해 공유


into (C# 레퍼런스)

컨텍스트 키워드를 into 사용하여 그룹, 조인, 선택 절의 결과를 새 식별자에 저장하기 위한 임시 식별자를 만들 수 있습니다. 이 식별자 자체는 추가 쿼리 명령에 대한 생성기일 수 있습니다. group 또는 select 절에서 사용할 때, 새 식별자의 사용을 때때로 연속이라고도 합니다.

예시

다음 예제에서는 키워드를 into 사용하여 유추된 형식IGrouping의 임시 식별자를 fruitGroup 사용하도록 설정하는 방법을 보여 줍니다. 식별자를 사용하여 각 그룹에서 메서드를 Count 호출하고 두 개 이상의 단어가 포함된 그룹만 선택할 수 있습니다.

class IntoSample1
{
    static void Main()
    {

        // Create a data source.
        string[] words = ["apples", "blueberries", "oranges", "bananas", "apricots"];

        // Create the query.
        var wordGroups1 =
            from w in words
            group w by w[0] into fruitGroup
            where fruitGroup.Count() >= 2
            select new { FirstLetter = fruitGroup.Key, Words = fruitGroup.Count() };

        // Execute the query. Note that we only iterate over the groups,
        // not the items in each group
        foreach (var item in wordGroups1)
        {
            Console.WriteLine($" {item.FirstLetter} has {item.Words} elements.");
        }
    }
}
/* Output:
   a has 2 elements.
   b has 2 elements.
*/

group 절의 into 사용은 각 그룹에 대해 추가로 쿼리 작업을 수행하려는 경우에만 필요합니다. 자세한 내용은 그룹 절을 참조하세요.

into의 사용 예는 join 절에서 join 절을 참조하십시오.

참고하십시오