c# advanced topics and future - c#5
DESCRIPTION
C# 3.0 Language EnhancementC# 4.0 Language EnhancementC# 5What is LINQ?LINQ Project GoalsLINQ Project ArchitectureData Binding via LINQTRANSCRIPT
![Page 1: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/1.jpg)
Developing Windows and Web Applications using Visual Studio.NET
Peter Gfader
![Page 2: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/2.jpg)
Who did the C# tutorial?
What is .NET?
What is the .NET framework?
What is the CLR?
What is OOP?
Session 1: Last week
![Page 3: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/3.jpg)
Agenda
C# 3.0 Language Enhancement
C# 4.0 Language Enhancement
C# 5
What is LINQ?
LINQ Project Goals
LINQ Project Architecture
Data Binding via LINQ
Session 2: Overview
![Page 4: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/4.jpg)
C# 32008
![Page 5: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/5.jpg)
Local Variable Type Interface
Anonymous Type
Lambda Expressions
Extension methods
Object initializers
Query Expressions
C# 3.0 Language Enhancement
![Page 6: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/6.jpg)
Local Variable Type Inference
![Page 7: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/7.jpg)
Fits with complex temporarily variables
E.g. I want a temp variable to hold username & password
Anonymous Type
![Page 8: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/8.jpg)
Anonymous methods in C#2
NumericalOperation mul1 = (x, y) => x * y;
Console.WriteLine( mul1(4, 5) );
Lambda Expressions
![Page 9: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/9.jpg)
Extend every class with a static „helper“ method
Extension methods
![Page 10: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/10.jpg)
More
Object initializer’s
Query Expressions
Please visit:
HookedOnLINQ.com
![Page 11: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/11.jpg)
C# 4April 2010
![Page 12: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/12.jpg)
„dynamic“ keyword
Optional parameters
Named parameters
Co and Contra variance
C# 4 Language Enhancement
![Page 13: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/13.jpg)
Co and Contra varianceHow are generic types “broken” today?
var sheep = new List<Sheep>(); Speak(sheep);
void Speak(IEnumerable<Animal> animals) { // Do something with Animals }
class Animal { } class Sheep : Animal { }
Not Allowed:IEnumerable<Animal> != IEnumerable<Sheep>
![Page 14: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/14.jpg)
Covariance – think “out”
Contravariance – think “in”
Break it down…
![Page 15: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/15.jpg)
C# 5????? 2013 ????
![Page 16: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/16.jpg)
„Meta programming is painful”
Compiler as a service
C# 5 ? - Release date?
![Page 17: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/17.jpg)
Auto Implemented Properties
Collection Initializers
Named parameters
Optional parameters
Lambdas
Can span statements across multiple lines
Auto Implemented Properties
Collection Initializers (limited)
Named parameters
Optional parameters
Lambdas (limited)
Can span statements across multiple lines
.NET 3.5
![Page 18: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/18.jpg)
Auto Implemented Properties
Collection Initializers
Named parameters
Optional parameters
Lambdas
Can span statements across multiple lines
Auto Implemented Properties
Collection Initializers
Named parameters
Optional parameters
Lambdas
Can span statements across multiple lines
.NET 4
![Page 19: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/19.jpg)
Data accessShow me the data!
![Page 20: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/20.jpg)
The problem
![Page 21: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/21.jpg)
Problem
![Page 22: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/22.jpg)
First showcased at the American International Toy Fair in New York in 2005
LINQ, a clever bluffing game
What is LINQ?
![Page 23: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/23.jpg)
Language INtegrated Query
Allows you to easily query information about an object
LINQ to SQL: An ORM made by Microsoft LINQ to Entities: Another ORM made by Microsoft LINQ to XML: Query over XML ...
What is LINQ?
![Page 24: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/24.jpg)
Language syntax+ a library of extension methods+ lambda expressions+ anonymous types+ a little magic
What is LINQ?
![Page 25: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/25.jpg)
.NET Framework 3.5
![Page 26: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/26.jpg)
LINQ is a natural language extension, part of .NET 3.5
Different data sources are queried with the same syntax.
Queries are strongly typed
Queries benefit from “Intellisense”
Applications becomes less error prone
LINQ - How does it solve the problem?
![Page 27: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/27.jpg)
Unified programming model for any data type
Database Relational Data XML Files Collections & Arrays
Introduce more declarative syntax
Helps the system find the best execution strategy
LINQ Project Goals
![Page 28: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/28.jpg)
LINQ Enabled Data Sources
LINQ Enabled ADO.NET
C# VB Others...
.NET Language Integrated Query (LINQ)
LINQ to
Objects
LINQ to Dataset
s
LINQ to
SQL
LINQ to
Entities
LINQ to
XML
LINQ to ??
?
<book> <title>
<author/> <price
/> </title></book>
Objects Database XML
LINQ Project Architecture
![Page 29: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/29.jpg)
LINQ Query
![Page 30: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/30.jpg)
string strSQL = “SELECT custID FROM Customers“;
SqlCommand cmd = new SqlCommand(strSQL, cnn);
SqlDataAdapter adAdapter = new SqlDataAdapter(cmd);
DataSet dst = new DataSet();
adAdapter.Fill(dst);
Standard Data Access Code
![Page 31: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/31.jpg)
NorthwindDataContext db = new NorthwindDataContext();
var customers = from c in db.Customers
select c;
Code by LINQ
![Page 32: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/32.jpg)
How to use LINQ
![Page 33: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/33.jpg)
Benefits from LINQ
LINQ data binding
LINQ
![Page 34: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/34.jpg)
Stored procedures are easier to work with
Relationship editor UI is nicer (more like SQL Server)
Performance
In a recent benchmark LINQ to SQL performed 5 times faster than LINQ to Entities
LINQ 2 SQL
![Page 35: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/35.jpg)
More refined ORM than LINQ to SQL
Many to Many relationships
Richer support for Inheritance
Validation
Update model from database
Mapping Editor
LINQ 2 Entities
![Page 36: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/36.jpg)
Do you know why you should choose "LINQ to Entities" over "LINQ to SQL"?
http://www.ssw.com.au/ssw/Standards/Rules/RulesToBetterLINQ.aspx#WhyLINQtoEntitiesNotSQL
What to choose?
![Page 38: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/38.jpg)
New features in C# 3.0
New features in C# 4.0
What is LINQ and Why LINQ
LINQ data binding
Summary
![Page 39: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/39.jpg)
Introduction to LINQ http://msdn.microsoft.com/en-us/library/bb397897.aspx
Getting Started with LINQ in C# http://msdn.microsoft.com/en-us/library/bb397933.aspx
LINQ Term and more details http://www.hookedonlinq.com/
LinqPad http://www.linqpad.net/
Resources
![Page 40: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/40.jpg)
What's next?
![Page 41: C# advanced topics and future - C#5](https://reader035.vdocument.in/reader035/viewer/2022062513/554eb98ab4c905fb7c8b564c/html5/thumbnails/41.jpg)
Thank You!
Gateway Court Suite 10 81 - 91 Military Road Neutral Bay, Sydney NSW 2089 AUSTRALIA
ABN: 21 069 371 900
Phone: + 61 2 9953 3000 Fax: + 61 2 9953 3105