c 3 0 linq n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
C# 3.0 & LINQ PowerPoint Presentation
Download Presentation
C# 3.0 & LINQ

Loading in 2 Seconds...

  share
play fullscreen
1 / 28
zeki

C# 3.0 & LINQ - PowerPoint PPT Presentation

245 Views
Download Presentation
C# 3.0 & LINQ
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. C# 3.0 & LINQ 천호민 Visual C# MVP zmeun.tistory.com

  2. Agenda Part Ⅰ: C# 3.0 New Features Part Ⅱ : Functional Programming Part Ⅲ : LINQ (Language Integrated Query)

  3. C# 3.0 New Features Var Local Variable • Anonymous Type • Auto-Implemented Properties • Object and Collection Initializer • Partial Method • Extension Method

  4. Demo: C#3.0 New Features

  5. Functional Programming >> Question… : What is the Functional Programming? Answer is … • Paradigm of the Software Programming • Avoid State and Mutable Data • So, Contrast with the Imperative Programming Style (변하기 쉬운) (피하다) (대조되다,대조하다) (명령적인)

  6. Functional Programming >> The Foundation Notions… First-Class Function Higher-Order Function Recursion Pure Function Curry Non-Stric & Lazy Evalution Closure

  7. Functional Programming >> Higher-Order & First-Class Function First-Class Function Higher-Order Function Recursion Pure Function -함수를 파라미터로 전달 받고 -결과를 함수로 리턴 -수학적인 컨셉과 컴퓨터 과학 용어의 차이 -Closure, Curry와 관련 Curry Non-Stric & Lazy Evalution Closure

  8. Functional Programming >> Pure Function First-Class Function -다른 프로그램에 영향을 주지 않는 개념 (Have No Side-Effect) -같은 결과를 리턴하는 함수 -참조로 전달된 파라미터 값을 수정하지 않고, -참조로 전달된 객체의 멤버 값을 수정하지 않고, -외부 객체, 클래스의 static 멤버 들을 수정하지 않는다. Higher-Order Function Recursion Pure Function Curry Non-Stric & Lazy Evaluation Closure

  9. Functional Programming >> Recursion First-Class Function -재귀호출이라 부르며 -자기 자신을 호출한다. -코드를 단순화 하며 -Higher-Order Function과 연관 Higher-Order Function Recursion Pure Function Curry Non-Stric & Lazy Evaluation Closure

  10. Functional Programming >> Non-Strict & Lazy Evaluation -엄격하지 않은 평가?, 게으른 평가? Ex) f(x)=x^2 + x + 1, g(x,y)=x + y Q) f(g(1,4)) 1:f(g(1,4)) -> f(1+4) -> f(5) -> 5^2 + 5 + 1 = 31 2:f(g(1,4))->g(1+4)^2+g(1,4)+1 ->(1+4)^2+(1+4)+1->5^2+5+1 = 31 -함수의 파라미터를 식(Expression) 으로 표현 -식의 반복 계산으로 Closure, Lazy Evaluation 필요. -Lazy Evaluation은 연산결과가 필요 할때 까지 계산을 지연시키는 기술 First-Class Function Higher-Order Function Recursion Pure Function Curry Non-Strict & Lazy Evaluation Closure

  11. Functional Programming >> Closure First-Class Function Higher-Order Function -하나의 함수내 또 다른 함수가 포함되어 있을때 생성 -외부 함수의 지역 변수를 내부 함수가 참조 가능 -숨겨진 상태를 처리.OOP에서도 사용 가능 -대게 First-Class Function에서 사용 Recursion Pure Function Curry Non-Strict & Lazy Evaluation Closure

  12. Functional Programming >> Curry First-Class Function Higher-Order Function -Curry? 맛있는 인도 음식? No! -다중 파라미터를 갖는 함수에서 실행 -연결된 함수의 리스트 -함수가 가지는 N개의 파라미터에 값을 모두 전달하지 않을 경우 함수가 리턴. 그 외의 경우 함수의 결과 값 리턴. -Closure, Higher-Order Function과 연관 Recursion Pure Function Curry Non-Strict & Lazy Evaluation Closure

  13. Demo: Functional Programming’s Foundation Notions

  14. - End of Session 1 -

  15. LINQ (Language-Integrated Query) LINQ Archetecture • Lambda Expression • Query Expression & Standard Query Operator • Expression Tree • Deffered Execution

  16. <book> <title/> <author/> <year/> <price/> </book> Relational Objects XML LINQ Archetecture .NET Language Integrated Query C# 3.0 Visual Basic 9.0 Others LINQ toObjects LINQ toDataSets LINQ toSQL LINQ toXML

  17. LINQ Lambda Expression • 식과 문을 포함하고 대리자(delegate)나 • 식 트리(Expression Tree) 형식을 • 만드는데 사용할 수 있는 익명 함수. • - C# 프로그래밍 가이드 - Syntax : public delegate TResult Func<T, TResult>(T arg) Lambda Operator , “=>” Operator : ex) Func<int, bool> isEven = n => n%2 == 0; Func<int, int, int> opSum = (n, m) => n+m; . . . . max argument to 5

  18. LINQ Query Expression & Standard Query Operator Starts with from Zero or more from, join, let, where, or orderby fromidinsource { fromidinsource | joinidinsourceonexprequalsexpr [ intoid ] | letid = expr | wherecondition | orderbyordering, ordering, … } selectexpr | groupexprbykey [ intoidquery ] Ends with select or groupby Optional into continuation

  19. LINQ Query Expression & Standard Query Operator • Queries translate to method invocations • Where, Join, OrderBy, Select, GroupBy, … from c in customers where c.Region == "WA" select new { c.City, c.Phone }; customers .Where(c => c.Region== "WA") .Select(c => new { c.City, c.Phone });

  20. LINQ Expression Tree >> public delegate bool Predicate<T>(T item); Expression<Predicate<Customer>> test = c => c.Region == "WA"; ParameterExpression c = Expression.Parameter(typeof(Customer), "c"); Expression expr = Expression.Equal( Expression.Property(c, typeof(Customer).GetProperty(“Region")), Expression.Constant("WA") ); Expression<Predicate<Customer>> test = Expression.Lambda<Predicate<Customer>>(expr, c);

  21. LINQ Expression Tree >> c => c.Region == "WA"; “c” Expression.Parameter “c.Region == ‘WA’” Expression.Equal “c.Region” Expression.Property “’WA’” Expression.Constant

  22. Demo: Building LINQ in C#3.0

  23. Simplicity C# 3.0 Feature Map Query expression var contacts = from c in customers where c.State == "WA" select new { c.City, c.Phone }; Expression tree Local variable type inference Automatic properties Lambda expression var contacts = customers .Where(c => c.State == "WA") .Select(c => new { c.City, c.Phone }); Partial method Extension method Anonymous type Object initializer

  24. Demo: Building LINQ in C#3.0Continue…

  25. - End of Session 2 -

  26. Resources • MSDN C# 3.0 Overviewhttp://msdn.microsoft.com/ko-kr/library/bb308966(en-us).aspx • MSDN .Net Frameworkhttp://msdn.microsoft.com/ko-kr/library/w0x726c2.aspx • MSDN Linq To SQLhttp://msdn.microsoft.com/ko-kr/library/bb386976.aspx • MSDN Linq Projecthttp://msdn.microsoft.com/ko-kr/netframework/aa904594(en-us).aspx • LINQ in Action Bloghttp://linqinaction.net/blogs/default.aspx • WikiPediahttp://en.wikipedia.org/wiki/Functional_programming

  27. Q&A

  28. Thanks…