첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.00MB

▶ Person.cs

namespace TestProject
{
    /// <summary>
    /// 인간
    /// </summary>
    public class Person
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 성명 - Name

        /// <summary>
        /// 성명
        /// </summary>
        public string Name { get; set; }

        #endregion
    }
}

 

728x90

 

▶ Student.cs

namespace TestProject
{
    /// <summary>
    /// 학생
    /// </summary>
    public class Student : Person
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 졸업 여부 - Graduated

        /// <summary>
        /// 졸업 여부
        /// </summary>
        public bool Graduated { get; set; }

        #endregion
    }
}

 

300x250

 

▶ Program.cs

using System;
using System.Collections.Generic;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            List<Person> list = new List<Person>();

            list.Add(new Student { Name = "홍길동", Graduated = true  });
            list.Add(new Student { Name = "김철수", Graduated = false });
            list.Add(new Student { Name = "이영희", Graduated = false });
            list.Add(new Student { Name = "홍길숙", Graduated = true  });

            IEnumerable<string> resultEnumerable = GetNameEnumerable(list);

            foreach(string name in resultEnumerable)
            {
                Console.WriteLine(name);
            }
        }

        #endregion
        #region 성명 열거 가능형 구하기 - GetNameEnumerable(personList)

        /// <summary>
        /// 성명 열거 가능형 구하기
        /// </summary>
        /// <param name="personList">인간 리스트</param>
        /// <returns>성명 열거 가능형</returns>
        private static IEnumerable<string> GetNameEnumerable(List<Person> personList)
        {
            foreach(Person person in personList)
            {
                if(person is Student { Graduated : false, Name : string name })
                {
                    yield return name;
                }
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요