C#: Future Directions in Language Innovation Anders Hejlsberg TLN307 Technical Fellow Microsoft Corporation.

Slides:



Advertisements
Similar presentations
The Microsoft Technical Roadshow 2007 Language Enhancements and LINQ Daniel Moth Developer & Platform Group Microsoft Ltd
Advertisements

Language Integrated Query (LINQ) Martin Parry Developer & Platform Group Microsoft Ltd
TeSLa researchproduct. Why The Visual Basic Imports SySTem.STriNg Module Demo Public Sub Main() Dim S = Join(", ", { "Hello", "World"}) End Sub.
LINQ and Collections An introduction to LINQ and Collections.
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.
© Logica All rights reserved ADO vNext LINQ LINQ to SQL Entity Framework Freek Leemhuis
C#/.NET 5/4/ Ian Cooper
1 Visual Studio 2008 Fons Sonnemans (Trainer) Reflection IT
ASP.NET 3.5 New Features. 2 Agenda What's New in.NET Framework 3.5? Visual Studio 2008 Enhancements LINQ (Language Integrated Query) New ASP.NET Server.
C# 3.0 & LINQ Raimond Brookman – IT Architect
LinqToSharePoint SandBoxed Solution Shakir Majeed Khan
1 Agenda Data and System Trends ChallengesObservationsConclusion.
LINQ: Language-Integrated Queries (To be included in C # 3.0) Technology developed by Anders Hejlsberg & friends at Microsoft (2005) Presented by Tal Cohen.
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.
A tour of new features introducing LINQ. Agenda of LINQ Presentation We have features for every step of the way LINQ Fundamentals Anonymous Functions/Lambda.
LINQ Programming in C# LINQ CSE Prof. Roger Crawfis.
 Introduction  What is LINQ  Syntax  How to Query  Example Program.
Reflection IT LINQ & Entity Framework Fons Sonnemans (Trainer)
Extension Methods Programming in C# Extension Methods CSE Prof. Roger Crawfis.
LINQ, An IntroLINQ, An Intro Florin−Tudor Cristea, Microsoft Student Partner.
Eric Vogel Software Developer A.J. Boggs & Company.
Advanced .NET Programming I 13th Lecture
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 11 th Lecture Pavel Ježek
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# 3.0 and.NET 3.5: A Brief Overview Pavel Ježek.
C# 3.0 & LINQ 천호민 Visual C# MVP zmeun.tistory.com.
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 and C# 3.0 Mads Torgersen Program Manager for the C# Language Microsoft Corporation.
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.
2008.NET iSDC & RONUA Workshop, November 10 th Mark Blomsma Software architect Develop-One.
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
C# 2.0 and Future Directions Anders Hejlsberg Technical Fellow Microsoft Corporation.
C# 3.0 and LINQ Pavel Yosifovich CTO, Hi-Tech College
Microsoft TechDayshttp:// Роман Здебский Эксперт по технологиям разработки ПО Microsoft
Lambda Expressions Version 1.0
Language Integrated Query (LINQ). Data Access Programming Challenges Developers must learn data store-specific query syntax Multiple, disparate data stores.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 10 th Lecture Pavel Ježek
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#
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Satisfy Your Technical Curiosity C# 3.0 Raj Pai Group Program Manager Microsoft Corporation
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.
Jonathan Aneja Program Manager Microsoft Corporation Session Code: DTL336 Anders Hejlsberg Technical Fellow Microsoft Corporation.
Ken Casada Developer Evangelist Microsoft Switzerland
Language Integrated Query Mike Taulty Developer & Platform Group Microsoft Ltd
Luke Hoban Senior Program Manager Microsoft Session Code: DTL319.
Part 1: Overview of LINQ Intro to LINQ Presenter: PhuongNQK.
Lambda Expressions Version 1.1
Tech·Ed North America /18/2018 2:05 PM
Lambda Expressions By Val Feldsher.
LINQ  LINQ – Language INtegrated Query  ( заявки вградени в езика )
Upgrading Your C# Programming Skills to Be a More Effective Developer
Advanced .NET Programming I 6th Lecture
9/20/2018 2:13 PM Visual Studio развитие технологий доступа к данным на платформе Microsoft.NET Роман Здебский Эксперт по технологиям разработки.
Language Integrated Query (LINQ)
Visual Studio “Orcas” & .NET Framework v3.5
Language Integrated Query (LINQ)
LINQ & ADO.NET Entity Framework
Технологии доступа к данным на платформе Microsoft.NET
LINQ - 2 Ravi Kumar C++/C# Team.
Advanced .NET Programming I 7th Lecture
Advanced .NET Programming I 4th Lecture
Advanced .NET Programming I 6th Lecture
Presentation transcript:

C#: Future Directions in Language Innovation Anders Hejlsberg TLN307 Technical Fellow Microsoft Corporation

The LINQ Project Standard Query Operators Objects DLinq (ADO.NET) XLinq(System.Xml) XML.NET Language Integrated Query C#VBOthers… SQLWinFS

C# 3.0 Design Goals Integrate objects, relational, and XML Build on foundation laid in C# 1.0 and 2.0 Run on the.NET 2.0 (“Whidbey”) CLR Don’t tie language to specific APIs Remain 100% backwards compatible

4 Language Integrated Query

5 C# 3.0 Language Innovations var contacts = from c in customers from c in customers where c.State == "WA" where c.State == "WA" select new { c.Name, c.Phone }; select new { c.Name, c.Phone }; var contacts = customers customers.Where(c => c.State == "WA").Where(c => c.State == "WA").Select(c => new { c.Name, c.Phone });.Select(c => new { c.Name, c.Phone }); Extension methods Lambda expressions Query expressions Object initializers Anonymous types Local variable type inference

6 public delegate bool Predicate (T obj); public class List public class List { public List FindAll(Predicate test) { … } public List FindAll(Predicate test) { … } …} Lambda Expressions List customers = GetCustomerList(); List x = customers.FindAll( delegate(Customer c) { return c.State == "WA"; } delegate(Customer c) { return c.State == "WA"; }); List x = customers.FindAll(c => c.State == "WA"); Explicitly typed Statement context Implicitly typed Expression context

7 Lambda Expressions public delegate T Func (); public delegate T Func (A0 arg0); public delegate T Func (A0 arg0, A1 arg1); … Func test = c => c.State == "WA"; Func f = (x, y) => x * y; Func comparer = (int x, int y) => { (int x, int y) => { if (x > y) return 1; if (x > y) return 1; if (x < y) return -1; if (x < y) return -1; return 0; return 0; }; }; double factor = 2.0; Func f = x => x * factor;

8 Queries Through APIs public class List public class List { public List Where(Func predicate) { … } public List Where(Func predicate) { … } public List Select (Func selector) { … } public List Select (Func selector) { … } …} List customers = GetCustomerList(); List contacts = customers.Where(c => c.State == "WA").Select(c => c.Name); customers.Where(c => c.State == "WA").Select(c => c.Name); Query operators are just methods Type inference figures out Type inference figures out But what about other types? Declare operators in all collections? What about arrays? Methods compose to form queries

9 Queries Through APIs public static class Sequence { public static IEnumerable Where (IEnumerable source, public static IEnumerable Where (IEnumerable source, Func predicate) { … } Func predicate) { … } public static IEnumerable Select (IEnumerable source, public static IEnumerable Select (IEnumerable source, Func selector) { … } Func selector) { … } …} Customer[] customers = GetCustomerArray(); IEnumerable contacts = Sequence.Select( Sequence.Where(customers, c => c.State == "WA"), Sequence.Where(customers, c => c.State == "WA"), c => c.Name); c => c.Name); Query operators are static methods Huh? Want methods on IEnumerable Want methods on IEnumerable

10 namespace System.Query { public static class Sequence public static class Sequence { public static IEnumerable Where (this IEnumerable source, public static IEnumerable Where (this IEnumerable source, Func predicate) { … } Func predicate) { … } public static IEnumerable Select (this IEnumerable source, public static IEnumerable Select (this IEnumerable source, Func selector) { … } Func selector) { … } … }} Extension Methods using System.Query; Extension methods IEnumerable contacts = customers.Where(c => c.State == "WA").Select(c => c.Name); customers.Where(c => c.State == "WA").Select(c => c.Name); Brings extensions into scope obj.Foo(x, y)  XXX.Foo(obj, x, y) IntelliSense!

11 Lambda Expressions and Extension Methods

12 Object Initializers public class Point { private int x, y; private int x, y; public int X { get { return x; } set { x = value; } } public int X { get { return x; } set { x = value; } } public int Y { get { return y; } set { y = value; } } public int Y { get { return y; } set { y = value; } }} Point a = new Point { X = 0, Y = 1 }; Point a = new Point(); a.X = 0; a.Y = 1; Field or property assignments

13 Object Initializers public class Rectangle { private Point p1 = new Point(); private Point p1 = new Point(); private Point p2 = new Point(); private Point p2 = new Point(); public Point P1 { get { return p1; } } public Point P1 { get { return p1; } } public Point P2 { get { return p2; } } public Point P2 { get { return p2; } }} Rectangle r = new Rectangle { P1 = { X = 0, Y = 1 }, P1 = { X = 0, Y = 1 }, P2 = { X = 2, Y = 3 } P2 = { X = 2, Y = 3 }}; Rectangle r = new Rectangle(); r.P1.X = 0; r.P1.Y = 1; r.P2.X = 2; r.P2.Y = 3; Embedded objects No “new Point” Read-only properties

14 Collection Initializers List powers = new List { 1, 10, 100, 1000, }; Must implement ICollection Must implement ICollection List powers = new List (); powers.Add(1);powers.Add(10);powers.Add(100);powers.Add(1000);powers.Add(10000);

15 Collection Initializers public class Contact { private string name; private string name; private List phoneNumbers = new List (); private List phoneNumbers = new List (); public string Name { get { return name; } set { name = value; } } public string Name { get { return name; } set { name = value; } } public List PhoneNumbers { get { return phoneNumbers; } } public List PhoneNumbers { get { return phoneNumbers; } }} List contacts = new List { new Contact { new Contact { Name = "Chris Smith", Name = "Chris Smith", PhoneNumbers = { " ", " " } PhoneNumbers = { " ", " " } }, }, new Contact { new Contact { Name = "Bob Harris", Name = "Bob Harris", PhoneNumbers = { " " } PhoneNumbers = { " " } }};

16 Local Variable Type Inference int i = 5; string s = "Hello"; double d = 1.0; int[] numbers = new int[] {1, 2, 3}; Dictionary orders = new Dictionary (); var i = 5; var s = "Hello"; var d = 1.0; var numbers = new int[] {1, 2, 3}; var orders = new Dictionary (); “var” means same type as initializer

17 Anonymous Types public class Customer { public string Name; public string Name; public Address Address; public Address Address; public string Phone; public string Phone; public List Orders; public List Orders; …} public class Contact { public string Name; public string Name; public string Phone; public string Phone;} Customer c = GetCustomer(…); Contact x = new Contact { Name = c.Name, Phone = c.Phone }; Customer c = GetCustomer(…); var x = new { c.Name, c.Phone }; Customer c = GetCustomer(…); var x = new { Name = c.Name, Phone = c.Phone }; class ??? { public string Name; public string Name; public string Phone; public string Phone;} Projection style initializer

18 var contacts = from c in customers from c in customers where c.State == "WA" where c.State == "WA" select new { c.Name, c.Phone }; select new { c.Name, c.Phone }; Anonymous Types var contacts = customers. customers..Where(c => c.State == "WA“).Where(c => c.State == "WA“).Select(c => new { c.Name, c.Phone });.Select(c => new { c.Name, c.Phone }); class ??? { public string Name; public string Name; public string Phone; public string Phone;} IEnumerable<???> foreach (var c in contacts) { Console.WriteLine(c.Name); Console.WriteLine(c.Name); Console.WriteLine(c.Phone); Console.WriteLine(c.Phone);} ???

19 Query Expressions Language integrated query syntax from id in source { from id in source | where condition } [ orderby ordering, ordering, … ] select expr | group expr by key [ into id query ] Starts with from Zero or more from or where Optional orderby Ends with select or group by Optional into continuation

20 from c in customers where c.State == "WA" select new { c.Name, c.Phone }; customers.Where(c => c.State == "WA").Select(c => new { c.Name, c.Phone }); Query Expressions Queries translate to method invocations Where, Select, SelectMany, OrderBy, GroupBy

21 Expression Trees public class Northwind: DataContext { public Table Customers; public Table Customers; public Table Orders; public Table Orders; …} Northwind db = new Northwind(…); var query = from c in db.Customers where c.State == "WA" select c; Northwind db = new Northwind(…); var query = db.Customers.Where(c => c.State == "WA"); How does this get remoted? public class Table : IEnumerable public class Table : IEnumerable { public Table Where(Expression > predicate); public Table Where(Expression > predicate); …} Method asks for expression tree System.Expressions. Expression System.Expressions. Expression

22 Expression Trees Code as Data Func test = c => c.State == "WA"; Expression > test = c => c.State == "WA"; ParameterExpression c = Expression.Parameter(typeof(Customer), "c"); Expression.Parameter(typeof(Customer), "c"); Expression expr = Expression.EQ( Expression.EQ( Expression.Property(c, typeof(Customer).GetProperty("State")), Expression.Property(c, typeof(Customer).GetProperty("State")), Expression.Constant("WA") Expression.Constant("WA") ); ); Expression > test = Expression.Lambda >(expr, c); Expression.Lambda >(expr, c);

23 LINQ Tech Preview

24 C# 3.0 Language Innovations Lambda expressions Extension methods Local variable type inference Object initializers Anonymous types Query expressions Expression trees var x = 5; static void Dump(this object o); c => c.Name new Point { x = 1, y = 2 } new { c.Name, c.Phone } from … where … select Expression<T>

25 More Information WednesdayThursdayFriday TLN306 - LINQ Overview 1:45 PM - 3:00 PM Halls C & D TLN308 - VB :00 AM - 11:15 AM Room 411 DAT323 (R) - DLinq for SQL 8:30 AM - 9:45 AM Room 408 AB TLN307 - C# 3.0 3:15 PM - 4:30 PM Halls C & D TLN307 (R) - C# 3.0 2:15 PM - 3:30 PM Room 402 AB DAT324 - XLinq 10:30 AM -11:45 AM Room 408 AB DAT323 - DLinq for SQL 2:15 PM - 3:30 PM Room 152/153 (Hall F) PNL11 - LINQ Panel 1:00 PM - 2:30 PM Room 152/153 (Hall F) DAT312 - DLinq for WinFS 5:00 PM – 6:15 PM Room 515 AB Ask the Experts 6:30 PM - 9:00 PM Main Hall

© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.