정성태님 안녕하세요?
저는 C# 버젼이 나올 때 마다 코딩에 적용하고는 합니다. C# 6.0에 새로 추가된  (벌서 C# 7.0이 나오는 시점에서!)
Expression Bodied Properties(전 그냥 Property Lambda라고 하는) 동작 방식이 제가 예상했던 대로 동작하지 않아서 문의를 드리게 되었습니다.
아래는 제가 테스트 한 간단한 코드 입니다.
제가 이해했던 동작은 { get } 프로퍼티랑 동일해야 했습니다. 하지만, 결과는 예상외였는데요. C# 스팩 전체 문서를 보지는 않았지만, C# 6.0 new features 문서에서는 get 프로퍼티랑 동일하게 동작하는 것 처럼 표현되어 있었거든요.
아래의 결과는 Property Lambda를 썼을 떄, List목록의 원소 값을 수정해도 오류 없이 값이 반영되지 않는 것을 확인하였습니다.
람다 형태로 썼을 때, 아마도 Task 환경을 고려한 것 처럼 이해가 되는데요 (잘은 모르겠습니다)
관련하여 시간이 되시면 심층 분석을 의뢰 드립니다 ;;
감사합니다
----
    public class Program
    {
        public static void Main(string[] args)
        {
            var tc = new TestClass();
            Console.WriteLine(tc.LamdaPropertyList[0]);
            tc.LamdaPropertyList[0] = 10;
            Console.WriteLine(tc.LamdaPropertyList[0]);
            Console.WriteLine();
            // ----
            Console.WriteLine(tc.PrivateSetPropertyList[0]);
            tc.PrivateSetPropertyList[0] = 10;
            Console.WriteLine(tc.PrivateSetPropertyList[0]);
            Console.WriteLine();
            // ----
            Console.WriteLine(tc.OnlyGetPropertyList[0]);
            tc.OnlyGetPropertyList[0] = 10;
            Console.WriteLine(tc.OnlyGetPropertyList[0]);
            Console.WriteLine();
        }
    }
    public class TestClass
    {
        public List<int> LamdaPropertyList => new List<int>
        {
            1, 2, 3, 4, 5
        };
        public List<int> PrivateSetPropertyList { get; private set; } = new List<int>
        {
            1, 2, 3, 4, 5
        };
        public List<int> OnlyGetPropertyList { get; } = new List<int>
        {
            1, 2, 3, 4, 5
        };
    }
        
        
                    
                    
                    
                    
                    
    
                    
                    
                    
                    
                    
                
                    [최초 등록일: ]
                    [최종 수정일: 7/6/2016]