SlideShare a Scribd company logo
New C#3 Features (LINQ) – Part I 
Nico Ludwig (@ersatzteilchen)
2 
TOC 
● New C#3 Features – Part I 
– Focus of C#3 Features 
– Automatically implemented Properties 
– Object and Collection Initializers: new Ways to initialize Objects and Collections 
● Sources: 
– Jon Skeet, CSharp in Depth
3 
Changes in .Net 3/3.5 – Overview 
● .Net 3/3.5 runtime 
– All the .Net 3 and 3.5 features are based on .Net 2 features. 
– The CLR wasn't even changed, .Net 3.5 still uses a CLR 2 underneath. 
● .Net 3/3.5 libraries 
– Some new libraries have been added: 
● Windows Presentation Foundation (WPF) 
● Windows Communication Foundation (WCF) 
● Windows Workflow Foundation (WF) 
● Windows CardSpace 
– Some present APIs have been extended. 
● C#3 and VB9 got syntactical enhancements to cope with LINQ. 
– The compilers have been updated, but no changes to the CIL have been done.
4 
Which Aims does C#3 pursue? 
● Focus of C#3 features: 
– Enhance readability and reduce syntactic fluff. 
– Increase productivity: "less code that monkeys could write". 
– More expressiveness to support a functional programming style. 
– LINQ 
● C#3 requires the .Net 3.5 being installed at minimum. 
– As well as Visual Studio 2008 or newer for development. 
● In this presentation: 
– The new boilerplate features of C#3 will be examined.
5 
Automatically implemented Properties 
// Public property Age in C#1/C#2: 
private int _age; 
public int Age 
{ 
get { return _age; } 
set { _age = value; } 
} 
// New in C#3: Age as automatically implemented property: 
public int Age { get; set; } 
● C#3 allows the definition of properties with a simplified syntax. 
– OK, it can only be used to define simple get/set properties with bare backing fields. 
– A real no-brainer, it; reduces the amount of required code. 
– Idea taken from C++/CLI (trivial properties) and Objective-C (synthesized properties). 
– Gotcha: Automatically implemented properties can break serialization. 
– (Not available for indexers. Default values can't be specified on them explicitly.) 
● In principle field-like events are automatically implemented by default since C#1 
– The methods add and remove and the backing field can be implemented optionally.
6 
Automatic Properties and Object Initializers in Action 
<InitializerExamples> 
Presents automatically implemented properties and object 
initializers.
7 
Automatically implemented Properties 
// Public property Age in C#1/C#2: 
private int _age; 
public int Age 
{ 
get { return _age; } 
set { _age = value; } 
} 
// New in C#3: Age as automatically implemented property: 
public int Age { get; set; } 
● C#3 allows the definition of properties with a simplified syntax. 
– OK, it can only be used to define simple get/set properties with bare backing fields. 
– A real no-brainer, it; reduces the amount of required code. 
– Idea taken from C++/CLI (trivial properties) and Objective-C (synthesized properties). 
– Gotcha: Automatically implemented properties can break serialization. 
– (Not available for indexers. Default values can't be specified on them explicitly.) 
● In principle field-like events are automatically implemented by default since C#1 
– The methods add and remove and the backing field can be implemented optionally.
8 
Object Initializers 
● Object initializers: simplified initialization of properties during object creation. 
– Create a new object and initialize properties (and fields) with one expression. 
– Reduces the need for a bunch of overloaded ctors and conversion operators. 
– This single expression style supports functional paradigms required for LINQ. 
// Create a Person object and 
// set property Age in C#1/C#2: 
Person p = new Person(); 
p.Age = 42; 
// New equivalent in C#3: Create (dctor) a Person object and 
// set property Age with one expression as object initializer: 
Person p = new Person { Age = 42 }; 
// Our toy: class Person with some properties and ctors: 
public class Person 
{ 
public int Age { get; set; } 
public string Name { get; set; } 
public Person() {} 
public Person(string name) { Name = name; } 
} 
// Create a 2nd Person object, set property Age with an 
// object initializer and set Name with the ctor: 
Person p2 = new Person { Name = "Joe", Age = 32 }; 
/* or: */ Person p3 = new Person("Joe") { Age = 32 };
9 
More to come: Embedded Object Initializers 
<InitializerExamples> 
Presents embedded object initializers.
10 
Embedded Object Initializers 
// Let's introduce a new type 'Location': 
public class Location 
{ 
// Just these two properties: 
public string Country { get; set; } 
public string Town { get; set; } 
● Object initializers can be embedded as well. 
– But embedded objects can't be created, only initialized. I.e. Home must be created by Person (the 'new Location()' expression is 
executed in all ctors of Person)! 
// Here is class Person with a property 'Home' of type 'Location': 
public class Person 
{ 
// Field _home is created by all Person's ctors: 
private Location _home = new Location(); 
public Location Home { get { return _home; } } 
// Other properties (Age, Name) and ctors... 
} 
// Create a Person object and apply an object initializer on property Home; 
// initialize Home with an embedded object initializer for type Location: 
Person p = new Person 
{ 
// Apply object initializer in an embedded manner: 
Home = { Country = "US", Town = "Boston" } 
}; 
}
11 
Collection Initializers 
<InitializerExamples> 
Presents Collection Initializers.
12 
Hands on Collection Initializers 
// C#2's way to create and fill a List<string>: 
IList<string> names = new List<string>(); 
names.Add("Rose"); 
names.Add("Poppy"); 
names.Add("Daisy"); 
● Remarks on Collection initializers: 
// New in C#3: create (dctor) and initialize a 
// List<string> with a Collection initializer: 
IList<string> names = new List<string> 
{ 
// Calls the method Add(string) for three times. 
"Rose", "Poppy", "Daisy" 
}; 
– They look like array initializer expressions (braced and comma separated value lists). 
– Can be used in concert with any ctor of the Collection to be initialized. 
– Can be used locally or for initialization of members. 
– Render the construction and initialization of a Collection into one expression. 
● A Collection must fulfill some requirements to be used with Collection initializers: 
– The Collection must implement IEnumerable or IEnumerable<T>. 
– The Collection must provide any public overload (any signature) of method Add().
13 
More Collection Initializers and implicitly typed Arrays 
<InitializerExamples> 
Presents more Collection initializers and implicitly typed arrays.
14 
More on Collection Initializers and implicitly typed Arrays 
// Apply a Collection initializer on a Dictionary<string, int> in C#3: 
IDictionary<string, int> nameToAge = new Dictionary<string, int> 
{ 
// Calls the method Add(string, int) for three times. 
{"Rose", 31}, {"Poppy", 32}, {"Daisy", 24} 
}; 
● Any public overload of method Add() can be used to initialize Collections. 
– Additionally the Collection initializers can be used as embedded object initializers! 
// Assume we have a method with a string-array parameter: 
private void AwaitsAStringArray(string[] strings); 
// Pass a newly created array with an array initializer in C#1/2: 
AwaitsAStringArray(new string[] { "Monica", "Rebecca", "Lydia" }); 
// New in C#3: leave the type name away on the new keyword: 
AwaitsAStringArray(new[] { "Monica", "Rebecca", "Lydia" }); 
● This is a syntactic simplification, which is handy on passing arrays to methods. 
– In C#3 there exist situations, in which static types are unknown or anonymous. 
– Only allowed, if the initial array items can be implicitly converted to the same type.
15 
What is the Sense of these Features? 
● Removal of syntactical fluff. 
– There are many developers that longed for these simplifications. 
– Programmatic "creation" of test data is much simpler now. 
– Once again: functional, "one-expression"- programming style is possible. 
● Why is the functional style preferred? 
– Syntactically concise. 
– Contributes to LINQ's expressiveness. 
● Simplified initialization is the basis of the so-called "anonymous types" in C#3. 
– More to come in next lectures...
16 
Thank you!

More Related Content

What's hot

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
Mayank Jain
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan
 
Collectors in the Wild
Collectors in the WildCollectors in the Wild
Collectors in the Wild
José Paumard
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Scott Leberknight
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
Logan Chien
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分
bob_is_strange
 
Orthogonal Functional Architecture
Orthogonal Functional ArchitectureOrthogonal Functional Architecture
Orthogonal Functional Architecture
John De Goes
 
Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central Dispatch
Matteo Battaglio
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
Knolx session
Knolx sessionKnolx session
Knolx session
Knoldus Inc.
 
The Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana IsakovaThe Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana Isakova
Vasil Remeniuk
 
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Philip Schwarz
 
Parte II Objective C
Parte II   Objective CParte II   Objective C
Parte II Objective C
Paolo Quadrani
 
Lightening Talk: Model Cat Can Haz Scope?
Lightening Talk: Model Cat Can Haz Scope?Lightening Talk: Model Cat Can Haz Scope?
Lightening Talk: Model Cat Can Haz Scope?evenellie
 
MTL Versus Free
MTL Versus FreeMTL Versus Free
MTL Versus Free
John De Goes
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
David Gómez García
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
Codemotion
 
Kotlin
KotlinKotlin
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
John De Goes
 

What's hot (20)

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
 
Collectors in the Wild
Collectors in the WildCollectors in the Wild
Collectors in the Wild
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
iOS Session-2
iOS Session-2iOS Session-2
iOS Session-2
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分
 
Orthogonal Functional Architecture
Orthogonal Functional ArchitectureOrthogonal Functional Architecture
Orthogonal Functional Architecture
 
Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central Dispatch
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
The Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana IsakovaThe Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana Isakova
 
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
 
Parte II Objective C
Parte II   Objective CParte II   Objective C
Parte II Objective C
 
Lightening Talk: Model Cat Can Haz Scope?
Lightening Talk: Model Cat Can Haz Scope?Lightening Talk: Model Cat Can Haz Scope?
Lightening Talk: Model Cat Can Haz Scope?
 
MTL Versus Free
MTL Versus FreeMTL Versus Free
MTL Versus Free
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
Kotlin
KotlinKotlin
Kotlin
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
 

Viewers also liked

Employees Background Check
Employees Background CheckEmployees Background Check
Employees Background CheckQamar Sir Nawaz
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
Nico Ludwig
 
Introduction to Linq
Introduction to LinqIntroduction to Linq
Introduction to Linq
Shahriar Hyder
 
New c sharp4_features_part_iii
New c sharp4_features_part_iiiNew c sharp4_features_part_iii
New c sharp4_features_part_iii
Nico Ludwig
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
Nico Ludwig
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
BlackRabbitCoder
 
Mohammad tijani smaoui ask those who know ex Sunni scholar
Mohammad tijani smaoui   ask those who know  ex Sunni scholarMohammad tijani smaoui   ask those who know  ex Sunni scholar
Mohammad tijani smaoui ask those who know ex Sunni scholar
rizwanamacha
 
Mohammad tijani smaoui the shia's are the real ahl e sunnah ex Sunni scholar
Mohammad tijani smaoui    the shia's are the real ahl e sunnah ex Sunni scholarMohammad tijani smaoui    the shia's are the real ahl e sunnah ex Sunni scholar
Mohammad tijani smaoui the shia's are the real ahl e sunnah ex Sunni scholar
rizwanamacha
 
Thyroide Eye Disease
Thyroide Eye DiseaseThyroide Eye Disease
Thyroide Eye Disease
Po Lindara
 
The Periodic Table
The Periodic TableThe Periodic Table
The Periodic Table
Celjhon Ariño
 
Akzo nobel competition_law_compliance_manual_tcm9-16085
Akzo nobel competition_law_compliance_manual_tcm9-16085Akzo nobel competition_law_compliance_manual_tcm9-16085
Akzo nobel competition_law_compliance_manual_tcm9-16085Dr Lendy Spires
 
a company of leaders.
a company of leaders.a company of leaders.
a company of leaders.
gandemallesudheer
 
Co crystalization
Co crystalizationCo crystalization
Co crystalization
Sujit Kale
 

Viewers also liked (15)

Employees Background Check
Employees Background CheckEmployees Background Check
Employees Background Check
 
C# features
C# featuresC# features
C# features
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
 
Introduction to Linq
Introduction to LinqIntroduction to Linq
Introduction to Linq
 
New c sharp4_features_part_iii
New c sharp4_features_part_iiiNew c sharp4_features_part_iii
New c sharp4_features_part_iii
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 
Mohammad tijani smaoui ask those who know ex Sunni scholar
Mohammad tijani smaoui   ask those who know  ex Sunni scholarMohammad tijani smaoui   ask those who know  ex Sunni scholar
Mohammad tijani smaoui ask those who know ex Sunni scholar
 
Mohammad tijani smaoui the shia's are the real ahl e sunnah ex Sunni scholar
Mohammad tijani smaoui    the shia's are the real ahl e sunnah ex Sunni scholarMohammad tijani smaoui    the shia's are the real ahl e sunnah ex Sunni scholar
Mohammad tijani smaoui the shia's are the real ahl e sunnah ex Sunni scholar
 
Thyroide Eye Disease
Thyroide Eye DiseaseThyroide Eye Disease
Thyroide Eye Disease
 
The Periodic Table
The Periodic TableThe Periodic Table
The Periodic Table
 
Akzo nobel competition_law_compliance_manual_tcm9-16085
Akzo nobel competition_law_compliance_manual_tcm9-16085Akzo nobel competition_law_compliance_manual_tcm9-16085
Akzo nobel competition_law_compliance_manual_tcm9-16085
 
Dot net sssit ppt
Dot net sssit pptDot net sssit ppt
Dot net sssit ppt
 
a company of leaders.
a company of leaders.a company of leaders.
a company of leaders.
 
Co crystalization
Co crystalizationCo crystalization
Co crystalization
 

Similar to New c sharp3_features_(linq)_part_i

Objective c intro (1)
Objective c intro (1)Objective c intro (1)
Objective c intro (1)
David Echeverria
 
Constructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdfConstructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdf
LadallaRajKumar
 
Constructors and destructors in C++
Constructors and destructors in  C++Constructors and destructors in  C++
Constructors and destructors in C++
RAJ KUMAR
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
Keyur Vadodariya
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
Asim Rais Siddiqui
 
(4) cpp abstractions references_copies_and_const-ness
(4) cpp abstractions references_copies_and_const-ness(4) cpp abstractions references_copies_and_const-ness
(4) cpp abstractions references_copies_and_const-ness
Nico Ludwig
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
Rounak Samdadia
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
Jagan Mohan Bishoyi
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
lavparmar007
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
Atif AbbAsi
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
Akash Gawali
 
chapter-9-constructors.pdf
chapter-9-constructors.pdfchapter-9-constructors.pdf
chapter-9-constructors.pdf
study material
 
(2) collections algorithms
(2) collections algorithms(2) collections algorithms
(2) collections algorithms
Nico Ludwig
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
Dhaval Kaneria
 
Learning C++ - Class 4
Learning C++ - Class 4Learning C++ - Class 4
Learning C++ - Class 4
Ali Aminian
 
While writing program in any language, you need to use various variables to s...
While writing program in any language, you need to use various variables to s...While writing program in any language, you need to use various variables to s...
While writing program in any language, you need to use various variables to s...
bhargavi804095
 
11-Classes.ppt
11-Classes.ppt11-Classes.ppt
11-Classes.ppt
basavaraj852759
 
c#(loops,arrays)
c#(loops,arrays)c#(loops,arrays)
c#(loops,arrays)
sdrhr
 
(3) cpp abstractions more_on_user_defined_types
(3) cpp abstractions more_on_user_defined_types(3) cpp abstractions more_on_user_defined_types
(3) cpp abstractions more_on_user_defined_types
Nico Ludwig
 

Similar to New c sharp3_features_(linq)_part_i (20)

Objective c intro (1)
Objective c intro (1)Objective c intro (1)
Objective c intro (1)
 
Constructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdfConstructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdf
 
Constructors and destructors in C++
Constructors and destructors in  C++Constructors and destructors in  C++
Constructors and destructors in C++
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 
(4) cpp abstractions references_copies_and_const-ness
(4) cpp abstractions references_copies_and_const-ness(4) cpp abstractions references_copies_and_const-ness
(4) cpp abstractions references_copies_and_const-ness
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
chapter-9-constructors.pdf
chapter-9-constructors.pdfchapter-9-constructors.pdf
chapter-9-constructors.pdf
 
(2) collections algorithms
(2) collections algorithms(2) collections algorithms
(2) collections algorithms
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
 
Learning C++ - Class 4
Learning C++ - Class 4Learning C++ - Class 4
Learning C++ - Class 4
 
While writing program in any language, you need to use various variables to s...
While writing program in any language, you need to use various variables to s...While writing program in any language, you need to use various variables to s...
While writing program in any language, you need to use various variables to s...
 
11-Classes.ppt
11-Classes.ppt11-Classes.ppt
11-Classes.ppt
 
c#(loops,arrays)
c#(loops,arrays)c#(loops,arrays)
c#(loops,arrays)
 
(3) cpp abstractions more_on_user_defined_types
(3) cpp abstractions more_on_user_defined_types(3) cpp abstractions more_on_user_defined_types
(3) cpp abstractions more_on_user_defined_types
 

More from Nico Ludwig

Grundkurs fuer excel_part_v
Grundkurs fuer excel_part_vGrundkurs fuer excel_part_v
Grundkurs fuer excel_part_v
Nico Ludwig
 
Grundkurs fuer excel_part_iv
Grundkurs fuer excel_part_ivGrundkurs fuer excel_part_iv
Grundkurs fuer excel_part_iv
Nico Ludwig
 
Grundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iiiGrundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iii
Nico Ludwig
 
Grundkurs fuer excel_part_ii
Grundkurs fuer excel_part_iiGrundkurs fuer excel_part_ii
Grundkurs fuer excel_part_ii
Nico Ludwig
 
Grundkurs fuer excel_part_i
Grundkurs fuer excel_part_iGrundkurs fuer excel_part_i
Grundkurs fuer excel_part_i
Nico Ludwig
 
(2) gui drawing
(2) gui drawing(2) gui drawing
(2) gui drawing
Nico Ludwig
 
(2) gui drawing
(2) gui drawing(2) gui drawing
(2) gui drawing
Nico Ludwig
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
Nico Ludwig
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
Nico Ludwig
 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_vi
Nico Ludwig
 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_ii
Nico Ludwig
 
New c sharp4_features_part_i
New c sharp4_features_part_iNew c sharp4_features_part_i
New c sharp4_features_part_i
Nico Ludwig
 
New c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_vNew c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_v
Nico Ludwig
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
Nico Ludwig
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNico Ludwig
 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iii
Nico Ludwig
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_ii
Nico Ludwig
 
Review of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiReview of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iii
Nico Ludwig
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_ii
Nico Ludwig
 
Review of c_sharp2_features_part_i
Review of c_sharp2_features_part_iReview of c_sharp2_features_part_i
Review of c_sharp2_features_part_i
Nico Ludwig
 

More from Nico Ludwig (20)

Grundkurs fuer excel_part_v
Grundkurs fuer excel_part_vGrundkurs fuer excel_part_v
Grundkurs fuer excel_part_v
 
Grundkurs fuer excel_part_iv
Grundkurs fuer excel_part_ivGrundkurs fuer excel_part_iv
Grundkurs fuer excel_part_iv
 
Grundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iiiGrundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iii
 
Grundkurs fuer excel_part_ii
Grundkurs fuer excel_part_iiGrundkurs fuer excel_part_ii
Grundkurs fuer excel_part_ii
 
Grundkurs fuer excel_part_i
Grundkurs fuer excel_part_iGrundkurs fuer excel_part_i
Grundkurs fuer excel_part_i
 
(2) gui drawing
(2) gui drawing(2) gui drawing
(2) gui drawing
 
(2) gui drawing
(2) gui drawing(2) gui drawing
(2) gui drawing
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_vi
 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_ii
 
New c sharp4_features_part_i
New c sharp4_features_part_iNew c sharp4_features_part_i
New c sharp4_features_part_i
 
New c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_vNew c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_v
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iii
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_ii
 
Review of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiReview of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iii
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_ii
 
Review of c_sharp2_features_part_i
Review of c_sharp2_features_part_iReview of c_sharp2_features_part_i
Review of c_sharp2_features_part_i
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 

New c sharp3_features_(linq)_part_i

  • 1. New C#3 Features (LINQ) – Part I Nico Ludwig (@ersatzteilchen)
  • 2. 2 TOC ● New C#3 Features – Part I – Focus of C#3 Features – Automatically implemented Properties – Object and Collection Initializers: new Ways to initialize Objects and Collections ● Sources: – Jon Skeet, CSharp in Depth
  • 3. 3 Changes in .Net 3/3.5 – Overview ● .Net 3/3.5 runtime – All the .Net 3 and 3.5 features are based on .Net 2 features. – The CLR wasn't even changed, .Net 3.5 still uses a CLR 2 underneath. ● .Net 3/3.5 libraries – Some new libraries have been added: ● Windows Presentation Foundation (WPF) ● Windows Communication Foundation (WCF) ● Windows Workflow Foundation (WF) ● Windows CardSpace – Some present APIs have been extended. ● C#3 and VB9 got syntactical enhancements to cope with LINQ. – The compilers have been updated, but no changes to the CIL have been done.
  • 4. 4 Which Aims does C#3 pursue? ● Focus of C#3 features: – Enhance readability and reduce syntactic fluff. – Increase productivity: "less code that monkeys could write". – More expressiveness to support a functional programming style. – LINQ ● C#3 requires the .Net 3.5 being installed at minimum. – As well as Visual Studio 2008 or newer for development. ● In this presentation: – The new boilerplate features of C#3 will be examined.
  • 5. 5 Automatically implemented Properties // Public property Age in C#1/C#2: private int _age; public int Age { get { return _age; } set { _age = value; } } // New in C#3: Age as automatically implemented property: public int Age { get; set; } ● C#3 allows the definition of properties with a simplified syntax. – OK, it can only be used to define simple get/set properties with bare backing fields. – A real no-brainer, it; reduces the amount of required code. – Idea taken from C++/CLI (trivial properties) and Objective-C (synthesized properties). – Gotcha: Automatically implemented properties can break serialization. – (Not available for indexers. Default values can't be specified on them explicitly.) ● In principle field-like events are automatically implemented by default since C#1 – The methods add and remove and the backing field can be implemented optionally.
  • 6. 6 Automatic Properties and Object Initializers in Action <InitializerExamples> Presents automatically implemented properties and object initializers.
  • 7. 7 Automatically implemented Properties // Public property Age in C#1/C#2: private int _age; public int Age { get { return _age; } set { _age = value; } } // New in C#3: Age as automatically implemented property: public int Age { get; set; } ● C#3 allows the definition of properties with a simplified syntax. – OK, it can only be used to define simple get/set properties with bare backing fields. – A real no-brainer, it; reduces the amount of required code. – Idea taken from C++/CLI (trivial properties) and Objective-C (synthesized properties). – Gotcha: Automatically implemented properties can break serialization. – (Not available for indexers. Default values can't be specified on them explicitly.) ● In principle field-like events are automatically implemented by default since C#1 – The methods add and remove and the backing field can be implemented optionally.
  • 8. 8 Object Initializers ● Object initializers: simplified initialization of properties during object creation. – Create a new object and initialize properties (and fields) with one expression. – Reduces the need for a bunch of overloaded ctors and conversion operators. – This single expression style supports functional paradigms required for LINQ. // Create a Person object and // set property Age in C#1/C#2: Person p = new Person(); p.Age = 42; // New equivalent in C#3: Create (dctor) a Person object and // set property Age with one expression as object initializer: Person p = new Person { Age = 42 }; // Our toy: class Person with some properties and ctors: public class Person { public int Age { get; set; } public string Name { get; set; } public Person() {} public Person(string name) { Name = name; } } // Create a 2nd Person object, set property Age with an // object initializer and set Name with the ctor: Person p2 = new Person { Name = "Joe", Age = 32 }; /* or: */ Person p3 = new Person("Joe") { Age = 32 };
  • 9. 9 More to come: Embedded Object Initializers <InitializerExamples> Presents embedded object initializers.
  • 10. 10 Embedded Object Initializers // Let's introduce a new type 'Location': public class Location { // Just these two properties: public string Country { get; set; } public string Town { get; set; } ● Object initializers can be embedded as well. – But embedded objects can't be created, only initialized. I.e. Home must be created by Person (the 'new Location()' expression is executed in all ctors of Person)! // Here is class Person with a property 'Home' of type 'Location': public class Person { // Field _home is created by all Person's ctors: private Location _home = new Location(); public Location Home { get { return _home; } } // Other properties (Age, Name) and ctors... } // Create a Person object and apply an object initializer on property Home; // initialize Home with an embedded object initializer for type Location: Person p = new Person { // Apply object initializer in an embedded manner: Home = { Country = "US", Town = "Boston" } }; }
  • 11. 11 Collection Initializers <InitializerExamples> Presents Collection Initializers.
  • 12. 12 Hands on Collection Initializers // C#2's way to create and fill a List<string>: IList<string> names = new List<string>(); names.Add("Rose"); names.Add("Poppy"); names.Add("Daisy"); ● Remarks on Collection initializers: // New in C#3: create (dctor) and initialize a // List<string> with a Collection initializer: IList<string> names = new List<string> { // Calls the method Add(string) for three times. "Rose", "Poppy", "Daisy" }; – They look like array initializer expressions (braced and comma separated value lists). – Can be used in concert with any ctor of the Collection to be initialized. – Can be used locally or for initialization of members. – Render the construction and initialization of a Collection into one expression. ● A Collection must fulfill some requirements to be used with Collection initializers: – The Collection must implement IEnumerable or IEnumerable<T>. – The Collection must provide any public overload (any signature) of method Add().
  • 13. 13 More Collection Initializers and implicitly typed Arrays <InitializerExamples> Presents more Collection initializers and implicitly typed arrays.
  • 14. 14 More on Collection Initializers and implicitly typed Arrays // Apply a Collection initializer on a Dictionary<string, int> in C#3: IDictionary<string, int> nameToAge = new Dictionary<string, int> { // Calls the method Add(string, int) for three times. {"Rose", 31}, {"Poppy", 32}, {"Daisy", 24} }; ● Any public overload of method Add() can be used to initialize Collections. – Additionally the Collection initializers can be used as embedded object initializers! // Assume we have a method with a string-array parameter: private void AwaitsAStringArray(string[] strings); // Pass a newly created array with an array initializer in C#1/2: AwaitsAStringArray(new string[] { "Monica", "Rebecca", "Lydia" }); // New in C#3: leave the type name away on the new keyword: AwaitsAStringArray(new[] { "Monica", "Rebecca", "Lydia" }); ● This is a syntactic simplification, which is handy on passing arrays to methods. – In C#3 there exist situations, in which static types are unknown or anonymous. – Only allowed, if the initial array items can be implicitly converted to the same type.
  • 15. 15 What is the Sense of these Features? ● Removal of syntactical fluff. – There are many developers that longed for these simplifications. – Programmatic "creation" of test data is much simpler now. – Once again: functional, "one-expression"- programming style is possible. ● Why is the functional style preferred? – Syntactically concise. – Contributes to LINQ's expressiveness. ● Simplified initialization is the basis of the so-called "anonymous types" in C#3. – More to come in next lectures...

Editor's Notes

  1. Windows CardSpace is a system to manage different identities against other environments, e.g. web sites. CardSpace is like your wallet with different cards representing different identities.
  2. .Net&amp;apos;s properties support the so called Unified Access Principle (UAP). UAP means that all the data of an object can be accessed and manipulated with the same syntax. Automatically implemented properties takes the UAP to the next level, because implementing properties is so easy now. Later on automatically implemented properties can be &amp;quot;promoted&amp;quot; to full properties in order to add logic to setters and getters. The gotcha: Serialization can depend on the names of the fields of a type getting serialized (this is esp. true for the BinaryFormatter, which is heavily used for .Net Remoting). And for automatically implemented properties the name of the field may change when the type is modified. So an instance&amp;apos;s data being serialized in past may no longer deserialize successfully later on, if the type has been modified in the meantime. Put simple: don&amp;apos;t use automatically implemented properties in serializable types! Automatically implemented properties are not suitable for immutable types as the backing field is always writeable. VB 10 supports auto-implemented properties with default values. Also present in Ruby with the attr_accessor generator method.
  3. .Net&amp;apos;s properties support the so called Unified Access Principle (UAP). UAP means that all the data of an object can be accessed and manipulated with the same syntax. Automatically implemented properties takes the UAP to the next level, because implementing properties is so easy now. Later on automatically implemented properties can be &amp;quot;promoted&amp;quot; to full properties in order to add logic to setters and getters. The gotcha: Serialization can depend on the names of the fields of a type getting serialized (this is esp. true for the BinaryFormatter, which is heavily used for .Net Remoting). And for automatically implemented properties the name of the field may change when the type is modified. So an instance&amp;apos;s data being serialized in past may no longer deserialize successfully later on, if the type has been modified in the meantime. Put simple: don&amp;apos;t use automatically implemented properties in serializable types! Automatically implemented properties are not suitable for immutable types as the backing field is always writeable. VB 10 supports auto-implemented properties with default values. Also present in Ruby with the attr_accessor generator method.
  4. The individually assigned properties/fields are assigned in exactly the order you write them in the object initializer. After assigning the last item in the object initializer, you are allowed to leave a dangling comma. You are not allowed to advise event handlers in an object initializer. If an exception is thrown on the initialization of a property/field the ctor is called, but the assigned-to symbol is only default initialized afterwards (as if the exception happened in the ctor). Resources being initialized with object or collection initializers within a using-context are not exception save (Dispose() won&amp;apos; be called). C++11 introduced uniform initialization, which addresses the same idea.
  5. The language specification refers to this as &amp;quot;setting the properties of an embedded object&amp;quot;. Also readonly fields can be initialized like this. The field _home could be created (new Location()) by any dedicated ctor as well to be functional with embedded object initializers.
  6. After assigning the last item of the anonymous type, you are allowed to leave a dangling comma (you can also leave it on arrays). In Objective-C there are so called container literals, which solve the same problem like C#&amp;apos;s Collection initializers.
  7. Under certain circumstances implicitly typed arrays can be initialized with initializer lists having mixed static types of their items: There must be one type into which all the initializer items can be converted to implicitly. Only the static types of initializer items&amp;apos; expressions are considered for this conversion. If these bullets do not meet, or if all the initializer items are typeless expressions (null literals or anonymous methods with no casts) the array initializer will fail to compile.