2 C# 1.0 C# 2.0 C# 3.0 Komponensek felügyelt környezetben • Property, delegate, event Típusbiztosabb, hatékonyabb nyelv • Generikus típusok, yield return.

Slides:



Advertisements
Similar presentations
Developer Knowledge Sharing Eric Sun Dec, What programming language did you learn in school and since then? Now, its time to refresh …
Advertisements

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
The Microsoft Technical Roadshow 2007 Language Enhancements and LINQ Daniel Moth Developer & Platform Group Microsoft Ltd
LINQ to objects. Datenmodell Zugriffsklasse Einfache Abfrage IEnumerable booksList = SampleDataAccess.DBooks.Select(b => b); Select(...) Book => object.
1 Visual C# "Whidbey": Language Enhancements Anders Hejlsberg Distinguished Engineer Microsoft Corporation Anders Hejlsberg Distinguished.
LINQ (Language Integrated Query)
Hilton Giesenow - The MOSS Show Developing with LINQ, REST & the New Client OM in Microsoft SharePoint 2010 SESSION CODE: OFC322.
0 PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions.
Modern Programming Languages, 2nd ed.
ML Lists.1 Standard ML Lists. ML Lists.2 Lists A list is a finite sequence of elements. [3,5,9] ["a", "list" ] [] Elements may appear more than once [3,4]
Dictionaries, Hash Tables, Collisions Resolution, Sets Svetlin Nakov Telerik Corporation
1 / / / /. 2 (Object) (Object) –, 10 (Class) (Class) –, –, – (Variables) [ Data member Field Attribute](, ) – (Function) [ Member function Method Operation.
Zoeken met Sitecore 7 Egbert Wietses pionect.nl.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
A Fourth Look At ML 1. Type Definitions Predefined, but not primitive in ML: Type constructor for lists: Defined for ML in ML datatype bool = true | false;
Deep Dive into LINQ Eran Sharabi.NET Development Team Leader JohnBryce Training
LINQ and Collections An introduction to LINQ and Collections.
... a programming language. ...a functional programming language.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Svetlin Nakov Telerik Corporation
.NET 3.5 – Mysteries. NetFx Evolution NetFx 1.0 C# 1.0, VB 7.0, VS.NET NetFx 1.1 C# 1.1, VB 7.1, VS 2003 NetFx 2.0 C# 2.0, VB 8.0, VS 2005 NetFx 3.0 C#
C# and LINQ Yuan Yu Microsoft Research Silicon Valley.
The Weakest LINQ: Querying the AutoCAD® Database James E. Johnson Software Developer CaptiveAire Systems Inc.
C# 3.0 & LINQ Raimond Brookman – IT Architect
Damien Guard (BSc, MBCS) Guernsey Software Developer Forum Language Integrated Query:
C# 3.0 Tom Roeder CS fa. Version 3 From PDC 2005 preview compiler available LINQ: language-integrated query High level points: adds native query.
2.3 Cool features in C# academy.zariba.com 1. Lecture Content 1.Extension Methods 2.Anonymous Types 3.Delegates 4.Action and Func 5.Events 6.Lambda Expressions.
LINQ Programming in C# LINQ CSE Prof. Roger Crawfis.
 Introduction  What is LINQ  Syntax  How to Query  Example Program.
Slides from Gang Luo, Xuting Zhao and Damien Guard
Reflection IT LINQ & Entity Framework Fons Sonnemans (Trainer)
LINQ, An IntroLINQ, An Intro Florin−Tudor Cristea, Microsoft Student Partner.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 11 th Lecture Pavel Ježek
Getting familiar with LINQ to Objects Florin−Tudor Cristea, Microsoft Student Partner.
Putting it all together: LINQ as an Example. The Problem: SQL in Code Programs often connect to database servers. Database servers only “speak” SQL. Programs.
Advanced C#, part IV Niels Hallenberg IT University of Copenhagen (With thanks to Peter Sestoft and Kasper Østerbye) BAAAP – Spring 2009.
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Based on material from Telerik Corporation.
Introduction to LINQ Lecture # 19 August Introduction How do you interrogate/manipulate data? What if you could do the work in a type-safe," string-free.
LINQ: It’s Not Your Father’s Data Access Denny Boynton Anheuser-Busch Companies.
The.NET Language Integrated Query Project Anders Hejlsberg TLN306 Technical Fellow Microsoft Corporation.
Neal Stublen How does XMLReader work?  XmlReader.Read() Advances to next node XmlReader properties access node name, value, attributes,
 Language Integrated Query  Make query a part of the language  Component of.NET Framework 3.5  Shipped with Visual Studio 2008.
C# 2.0 and Future Directions Anders Hejlsberg Technical Fellow Microsoft Corporation.
C#: Future Directions in Language Innovation Anders Hejlsberg TLN307 Technical Fellow Microsoft Corporation.
LINQ & PLINQ (Parallel) Language Integrated Query.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 10 th Lecture Pavel Ježek
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
Inside LINQ to Objects How LINQ to Objects work Inside LINQ1.
Introduction to C# 2.0 An Advanced Look Adam Calderon Principal Engineer - Interknowlogy Microsoft MVP – C#
Satisfy Your Technical Curiosity C# 3.0 Raj Pai Group Program Manager Microsoft Corporation
Linq Overview Vincent GERMAIN. Evolution - Rappel Langage  C# 2.0  C# 3.0 (Local type inference, Lambda expression, Method extension,Anonymous type)
Damien Guard (BSc, MBCS) Guernsey Software Developer Forum Language Integrated Query:
Joel Pobar Language Geek Microsoft DEV320 Improve on C# % Backwards Compatible Language Integrated Query (LINQ)
IAP C# 2011 Lecture 2: Delegates, Lambdas, LINQ Geza Kovacs.
Language Integrated Query Mike Taulty Developer & Platform Group Microsoft Ltd
LINQ and Lambda Expressions Telerik Software Academy LINQ Overview.
Functional Programming
Jim Fawcett CSE681 – Software Modeling and Analysis Fall 2016
Jim Fawcett CSE681 – Software Modeling and Analysis Fall 2013
Intro to LINQ Part 2 – Concepts and LINQ to Objects
Language Integrated Query: (LINQ) An introduction
Advanced .NET Programming I 6th Lecture
LINQ & ADO.NET Entity Framework
INFO 344 Web Tools And Development
LINQ - 2 Ravi Kumar C++/C# Team.
LINQ to SQL Part 3.
Advanced .NET Programming I 7th Lecture
Advanced .NET Programming I 6th Lecture
CS4540 Special Topics in Web Development LINQ to Objects
Presentation transcript:

2

C# 1.0 C# 2.0 C# 3.0 Komponensek felügyelt környezetben • Property, delegate, event Típusbiztosabb, hatékonyabb nyelv • Generikus típusok, yield return Nyelvbe ágyazott lekérdezések

public class List { T[] array = new T[10]; // tároló public void Add( T item ) { this.array[count++] = item; } public class List { T[] array = new T[10]; // tároló public void Add( T item ) { this.array[count++] = item; }

public IEnumerable Filter() { foreach( T t in this ) if( t.ToString().StartsWith( "S" ) ) yield return t; }... static void Main() {... foreach( int i in list.Filter() ) Console.WriteLine( i ); } public IEnumerable Filter() { foreach( T t in this ) if( t.ToString().StartsWith( "S" ) ) yield return t; }... static void Main() {... foreach( int i in list.Filter() ) Console.WriteLine( i ); }

public IEnumerable Filter( Predicate filter ) { foreach( T t in this ) if( filter( t ) ) yield return t; }... static void Main() {... foreach( int i in list.Filter( delegate( string s ) { return s.StartsWith( "S" ); } ) ) Console.WriteLine( i ); } public IEnumerable Filter( Predicate filter ) { foreach( T t in this ) if( filter( t ) ) yield return t; }... static void Main() {... foreach( int i in list.Filter( delegate( string s ) { return s.StartsWith( "S" ); } ) ) Console.WriteLine( i ); }

7

delegate( string s ) { return s.StartsWith( "S" ); } s => s.StartsWith( "S" ) ( x, y ) => Math.Sqrt( x * x + y * y ) () => 42

public class List { public int Count { get; private set; } public void Add( T item ) { this.array[Count++] = item; } public class List { public int Count { get; private set; } public void Add( T item ) { this.array[Count++] = item; } private int <>field0; public int Count { get { return <>field0; } private set { <>field0 = value; } } private int <>field0; public int Count { get { return <>field0; } private set { <>field0 = value; } }

namespace linqSample.Utils { public static class Helper { static public IEnumerable Filter( this IEnumerable seq, Predicate filter ) {... } namespace linqSample.Utils { public static class Helper { static public IEnumerable Filter( this IEnumerable seq, Predicate filter ) {... } Statikus bővítő metódus A bővítendő típus a ‘this’ kulcsszó után A névtérben lévő összes bővítőmetódus engedélyezése using linqSample.Utils;

List list = new List (); foreach( string x in list.Filter( s => s.StartsWith( "S" ) ) ) List list = new List (); foreach( string x in list.Filter( s => s.StartsWith( "S" ) ) ) var list = new List (); foreach( var x in list.Filter( s => s.StartsWith( "S" ) ) ) var list = new List (); foreach( var x in list.Filter( s => s.StartsWith( "S" ) ) )

12

var b=new Music{ Title="Soul Bop",Length=591 } new Music { Title = "Soul Bop", Length = 591 }. Dump(); list.Add( new Music { Title = "Soul Bop", Length = 591 } ); var b0=new Music(); b0.Title="Soul Bop"; b0.Length=591; var b = b0; var b0=new Music(); b0.Title="Soul Bop"; b0.Length=591; var b = b0;

new Music { Title = "Soul Bop", Length = 591, Album = { Artist = "Bill Evans", Year = 2000 } } new Music { Title = "Soul Bop", Length = 591, Album = { Artist = "Bill Evans", Year = 2000 } } new Music { Title = "Soul Bop", Length = 591, Album = new Album{ Artist = "Bill Evans", Year = 2000 } } new Music { Title = "Soul Bop", Length = 591, Album = new Album{ Artist = "Bill Evans", Year = 2000 } }

var szamok = new Dictionary { { 0, "nulla" }, { 1, "egy" }, { 2, "kettő" } }; var szamok = new Dictionary { { 0, "nulla" }, { 1, "egy" }, { 2, "kettő" } }; var v = new [ ] { 1, 1.5, 2.3 }; // double [ ] var list = new List { new Music { Title = "Soul Bop", Length = 591 }, new Music { Title = "Hangin' in the City", Length = 397 } }; var list = new List { new Music { Title = "Soul Bop", Length = 591 }, new Music { Title = "Hangin' in the City", Length = 397 } };

var list = new [ ] { new { Title = "Soul Bop", Length = 591 }, new { Title = "Hangin' in the City", Length = 397 } }; foreach( var x in list.Filter( s => s.Length < 300 ) ) Console.WriteLine( x ); var list = new [ ] { new { Title = "Soul Bop", Length = 591 }, new { Title = "Hangin' in the City", Length = 397 } }; foreach( var x in list.Filter( s => s.Length < 300 ) ) Console.WriteLine( x );

17

SzűrésWhere ProjekcióSelect, SelectMany RendezésOrderBy, ThenBy CsoportosításGroupBy JoinokJoin, GroupJoin QuantifiersAny, All ParticionálásTake, Skip, TakeWhile, SkipWhile HalmazműveletekDistinct, Union, Intersect, Except ElemekFirst, Last, Single, ElementAt AggregációCount, Sum, Min, Max, Average KonverzióToArray, ToList, ToDictionary KasztolásOfType, Cast

20

from m in list where m.Title.StartsWith( "S" ) select m. Title; from m in list where m.Title.StartsWith( "S" ) select m. Title; list.Where( m => m. Title.StartsWith( "S" ) ).Select( m => m.Title); list.Where( m => m. Title.StartsWith( "S" ) ).Select( m => m.Title);

from id in source { from id in source | join id in source on expr equals expr [ into id ] | let id = expr | where condition | orderby ordering, ordering, … } select expr | group expr by key [ into id query ] from-mal kezdődik További from, join, let, where, vagy orderby Végül select by group by Opcionálisan into-val folytatható A Query Expression Pattern metódusai Where Select, SelectMany OrderBy, OrderByDescending, ThenBy, ThenByDescending GroupBy Join, GroupJoin Cast

list TitleLengthID select m => m.Title cimek m => m.Title.StartsWith("S”) where var list = new List {... }; q.ToList(); var q = from m in list where m.Title.StartsWith( "S" ) select m.Title; var q = list.Where( m => m.Title.StartsWith( "S" ) ). Select( m => m.Title);

24

from m in list where m.Title.StartsWith( "S" ) select m.Title; SELECT Title FROM Musicok WHERE Title LIKE ‘S%’

Expression > expr = m => m.Title.StartsWith( "S" ); public delegate bool Predicate ( T obj ); ParameterExpression p= Expression.Parameter(typeof(Music),"m"); expr=Expression.Lambda >( Expression.Call( Expression.Property(p, GetMethod(Music.get_Title)), GetMethod(string.StartsWith), new Expression [ ] {Expression.Constant("S", typeof(string)) }), new ParameterExpression [ ] { p }); ParameterExpression p= Expression.Parameter(typeof(Music),"m"); expr=Expression.Lambda >( Expression.Call( Expression.Property(p, GetMethod(Music.get_Title)), GetMethod(string.StartsWith), new Expression [ ] {Expression.Constant("S", typeof(string)) }), new ParameterExpression [ ] { p });

27 public static IQueryable Where ( this IQueryable source, Expression > predicate); public static IQueryable Where ( this IQueryable source, Expression > predicate); list. Where(…). Take(…). Select (…); // végül egy Expression lesz

28 SELECT System.Title, System.Media.Duration FROM SystemIndex WHERE System.Title = 'Soul Bop'

29 new WDS(). Where( m => m.Title.StartsWith( "S" ) && m.Length > 300 ); MethodCall Where Object (root) WDS WDSLambdaExp m => … LambdaExp GreaterThan … > … GreaterThan MemberAccessm.LengthMemberAccessm.LengthConstant300Constant300 MethodCall ….StartsWith( … ) MethodCall MemberAccessm.TitleMemberAccessm.TitleConstant“S”Constant“S” AndAlso … && … AndAlso

System.Linq.Enumerable delegate alapú A forrás IEnumerable System.Linq.Queryable kifejezésfa alapú A forrás IQueryable SQL DataSet Objektumok Egyéb... from m in list where m.Title.StartsWith( "S" ) select m.Title; var q = list.Where( m => m.Title.StartsWith( "S" ) ). Select( m => m.Title);

31

var q = from m in list where m.Title.StartsWith( "S" ) select new { m.Title, m.Length }; var q = from m in list where m.Title.StartsWith( "S" ) select new { m.Title, m.Length }; var q = list.Where( m => m.Length.StartsWith( "S" ) ).Select( m => new { m.Title, m.Length } ); var q = list.Where( m => m.Length.StartsWith( "S" ) ).Select( m => new { m.Title, m.Length } ); Bővítő metódusok Lambda kifejezések Lekérdezések Objektum inicializálók Névtelen típusok Implicit típusú lokális változó

Objektumok XML.NET Language Integrated Query C# 3.0 VB 9.0 más nyelvek… Relációs adatbázisok LINQ to Objects LINQ to SQL LINQ to XML LINQ to Entities LINQ to DataSets

36

37

38

Func Sort = xs => xs.Case( () => xs, ( head,tail ) => ( Sort( tail.Where( x => x < head ) ) ).Concat ( Single( head ) ).Concat ( Sort( tail.Where( x => x >= head ) ) ) ); type inference összefűzés magasabb rendű funkció típussal paraméterezett funkció rekurzió szűrés lambda kifejezés

© 2007 Microsoft Corporation. Minden jog fenntartva. Az előadás csupán tájékoztató jellegű, a Microsoft Magyarország a benne szereplő esetleges hibákért vagy tévedésekért semmilyen felelősséget nem vállal.