Satisfy Your Technical Curiosity C# 3.0 Raj Pai Group Program Manager Microsoft Corporation

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

The Microsoft Technical Roadshow 2007 Language Enhancements and LINQ Daniel Moth Developer & Platform Group Microsoft Ltd
Language Integrated Query (LINQ) Martin Parry Developer & Platform Group Microsoft Ltd
LINQ and Collections An introduction to LINQ and Collections.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
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.
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
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.
C# 3.0 and LINQ Pavel Yosifovich CTO, Hi-Tech College
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
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.
The.NET Language Integrated Query Project Anders Hejlsberg TLN306 Technical Fellow Microsoft Corporation.
.NET 2.0 and Visual Studio 2005 SigWin Outline Language enhancements in C# Language enhancements in C# –Generics –Partial types –Anonymous methods.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
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.
Microsoft TechDayshttp:// Роман Здебский Эксперт по технологиям разработки ПО Microsoft
Lambda Expressions Version 1.0
C#: Future Directions in Language Innovation Anders Hejlsberg TLN307 Technical Fellow Microsoft Corporation.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
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#
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
Writing Better C# Using C# 6 By: Mitchel Sellers.
LINQ and Lambda Expressions Telerik Software Academy LINQ Overview.
Mark Michaelis Chief Computer Nerd IDesign/Itron/IntelliTechture DTL313.
Building Web Applications with Microsoft ASP
Part 1: Overview of LINQ Intro to LINQ Presenter: PhuongNQK.
Lambda Expressions Version 1.1
Tech·Ed North America /18/2018 2:05 PM
Upgrading Your C# Programming Skills to Be a More Effective Developer
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Advanced .NET Programming I 6th Lecture
9/20/2018 2:13 PM Visual Studio развитие технологий доступа к данным на платформе Microsoft.NET Роман Здебский Эксперт по технологиям разработки.
.NET and .NET Core 9. Towards Higher Order Pan Wuming 2017.
Language Integrated Query (LINQ)
Visual Studio “Orcas” & .NET Framework v3.5
LINQ & ADO.NET Entity Framework
Технологии доступа к данным на платформе Microsoft.NET
DEV322 Visual Studio 2005 C# IDE Enhancements
ADO.NET Entity Framework
LINQ - 2 Ravi Kumar C++/C# Team.
Advanced .NET Programming I 7th Lecture
Advanced .NET Programming I 6th Lecture
Chengyu Sun California State University, Los Angeles
CS4540 Special Topics in Web Development LINQ to Objects
Presentation transcript:

Satisfy Your Technical Curiosity C# 3.0 Raj Pai Group Program Manager Microsoft Corporation

Satisfy Your Technical Curiosity The Evolution of C# C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query

Satisfy Your Technical Curiosity C# 3.0 Design Goals Integrate objects, relational data, and XML Increase conciseness of language Add functional programming constructs Don’t tie language to specific APIs Remain 100% backwards compatible

Satisfy Your Technical Curiosity

Lambda Expressions public delegate bool Predicate (T obj); public class List { public List FindAll(Predicate test) { List result = new List (); foreach (T item in this) if (test(item)) result.Add(item); return result; } … }

Satisfy Your Technical Curiosity Lambda Expressions public class MyClass { public static void Main() { List customers = GetCustomerList(); List locals = customers.FindAll( new Predicate (StateEqualsWA) ); } static bool StateEqualsWA(Customer c) { return c.State == "WA"; }

Satisfy Your Technical Curiosity Lambda Expressions public class MyClass { public static void Main() { List customers = GetCustomerList(); List locals = customers.FindAll( delegate(Customer c) { return c.State == "WA"; } ); }

Satisfy Your Technical Curiosity Lambda Expressions public class MyClass { public static void Main() { List customers = GetCustomerList(); List locals = customers.FindAll(c => c.State == "WA"); } Lambda expression

Satisfy Your Technical Curiosity Extension Methods

Satisfy Your Technical Curiosity Extension Methods namespace MyStuff { public static class Extensions { public static string Concatenate(this IEnumerable strings, string separator) {…} } using MyStuff; string[] names = new string[] { "Axel", "Mia", "Niels" }; string s = names.Concatenate(", "); Extension method Brings extensions into scope obj.Foo(x, y)  XXX.Foo(obj, x, y) IntelliSense!

Satisfy Your Technical Curiosity Object Initializers

Satisfy Your Technical Curiosity Object Initializers public class Point { private int x, y; public int X { get { return x; } set { x = 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

Satisfy Your Technical Curiosity Collection Initializers List numbers = new List { 1, 10, 100 }; Must implement IEnumerable List numbers = new List (); numbers.Add(1); numbers.Add(10); numbers.Add(100); Must have public Add method Dictionary spellings = new Dictionary { { 0, "Zero" }, { 1, "One" }, { 2, "Two" }, { 3, "Three" } }; Add can take more than one parameter

Satisfy Your Technical Curiosity Anonymous Types

Satisfy Your Technical Curiosity IEnumerable phoneListQuery = from c in customers where c.State == "WA" select new Contact { Name = c.Name, Phone = c.Phone }; Anonymous Types public class Contact { public string Name; public string Phone; } +

Satisfy Your Technical Curiosity var phoneListQuery = from c in customers where c.State == "WA" select new { Name = c.Name, Phone = c.Phone }; Anonymous Types class XXX { public string Name; public string Phone; } IEnumerable foreach (var entry in phoneListQuery) { Console.WriteLine(entry.Name); Console.WriteLine(entry.Phone); } XXX

Satisfy Your Technical Curiosity Local Variable Type Inference

Satisfy Your Technical Curiosity 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 (); “The type on the right hand side”

Satisfy Your Technical Curiosity Query Expressions

Satisfy Your Technical Curiosity Query Expressions 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 ] Starts with from Zero or more from, join, let, where, or orderby Ends with select or group by Optional into continuation

Satisfy Your Technical Curiosity 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, Join, OrderBy, Select, GroupBy, …

Satisfy Your Technical Curiosity Expression Trees Code as Data Predicate test = c => c.State == "WA"; Predicate test = new Predicate (XXX); private static bool XXX(Customer c) { return c.State == "WA"; } public delegate bool Predicate (T item);

Satisfy Your Technical Curiosity Expression Trees Code as Data Expression > test = c => c.State == "WA"; public delegate bool Predicate (T item); ParameterExpression c = Expression.Parameter(typeof(Customer), "c"); Expression expr = Expression.Equal( Expression.Property(c, typeof(Customer).GetProperty("State")), Expression.Constant("WA") ); Expression > test = Expression.Lambda >(expr, c);

Satisfy Your Technical Curiosity Automatic Properties

Satisfy Your Technical Curiosity Automatic properties public class Product { public string Name; public decimal Price; }

Satisfy Your Technical Curiosity Automatic properties public class Product { string name; decimal price; public string Name { get { return name; } set { name = value; } } public decimal Price { get { return price; } set { price = value; } }

Satisfy Your Technical Curiosity Automatic properties public class Product { public string Name { get; set; } public decimal Price { get; set; } } private string □; public string Name { get { return □; } set { □ = value; } } Must have both get and set

Satisfy Your Technical Curiosity Partial Methods

Satisfy Your Technical Curiosity Partial Methods partial class Customer { public string Name { get { … } set { _name = value; }

Satisfy Your Technical Curiosity Partial Methods partial class Customer { public string Name { get { … } set { OnNameChanging(value); _name = value; OnNameChanged(); } partial void OnNameChanging(string value); partial void onNameChanged(); } Partial Method Call Partial Method Definition

Satisfy Your Technical Curiosity C# 3.0 Language Innovations var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone }; var contacts = customers.Where(c => c.State == "WA").Select(c => new { c.Name, c.Phone }); Extension methods Lambda expressions Query expressions Object initializers Anonymous types Local variable type inference Expression Trees Automatic Properties Partial Methods

Satisfy Your Technical Curiosity C# 3.0 Design Goals Integrate objects, relational data, and XML Increase conciseness of language Add functional programming constructs Don’t tie language to specific APIs Remain 100% backwards compatible

Satisfy Your Technical Curiosity

More Information WednesdayThursday DEV203 LINQ Overview 14:30 – 15:45 DEV307 C# 3.0 9:00 – 10:15 DEV205 Visual Studio Orcas 17:45 – 18:45 DEV204 ADO.NET vNext 10:45 – 12:00 DEV318 Visual Basic :00 – 14:15

Satisfy Your Technical Curiosity ©2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.