SlideShare une entreprise Scribd logo
1  sur  15
Visual Studio 2008 Training

                                       3.5 RTM




Mohamed Saleh
MohamedSaleh@live.com
www.jordev.net
www.geeksconnected.com/mohamed
Module 2:
C# 3.0 Language
 Enhancements
Overview


  Automate the process of creating properties
  Enhance the objects and collections using the
  Initializers
  Create implicitly typed local variables
  Extend existing types using Extension Methods
  Write the new lambda expressions
  Using the new features in multi-framework versions
Automatically Implemented Properties
              Auto-Implemented Properties Overview

  Auto-Implemented Properties can handle the trivial
  implementation of getter and setter.
  The compiler will generate hidden backing fields with the
  implementation.
  This feature is related to the compiler and not the
  Framework Version or the Intermediate Language.
  The Auto-Implemented Properties can be implemented
  using the following syntax:
         public string Name { get; set; }
Lab 1: Using Auto-Implemented Properties


              Using the Automatic Implemented
              Properties.
              Creating read-only and write-only
              properties.
              Using Automatic Implemented Properties
              with multi-framework versions.
              Examining the effects of the Automatic
              Implemented Properties on the generated
              intermediate language.
Object and Collection Initializers
                  Object Initializer Overview

   Object Initializers allows the developer to create the
   object instance and assign the initial values at the same
   time.
   The C# 2.0 way of initializing objects:
            Customer cst2 = new Customer();
            cst2.ID = 2;
            cst2.Name = "Ayman Farouk";
            cst2.Phone = "0799-987-980-98";

   The C# 3.0 way of initializing objects:
       Customer cst3 = new Customer()
      { ID = 3, Name = "Osama Salam", Phone = "074-545-545-67" };
Object and Collection Initializers
                      Collection Initializers Overview

   The collection Initializers allows the developer to specify
   one or more elements Initializers when initializing any
   type that implements the System.Collections.Generic.IEnumerable<T>.
   Initializers Rules:
    1.   Object Initializers cannot include more than one member initializer
         for the same field or property.
    2.   The Object Initializers cannot refer to the newly created object it is
         initializing.
    3.   The Collection type must implements
         System.Collections.Generic.IEnumerable<T> in order to have
         initializers.
Lab 2: Using Initializers


                Writing Object Initializer expressions.
                Writing Collection Initializer expressions.
                Using the nested object initializer.
                Using Initializers with multi-framework
                versions.
                Examining the generated initialization
                instructions in the intermediate language.
Implicit Typing
                  Implicit Typing Overview

   The new keyword var allows the C# compiler to infers
   the type of variables
   the compiler will determines the appropriate CLR type
   Var differ than variant keyword in VB6 and COM
   Implicit Typing Context:
    1. Declaring variable at the method/property scope
    2. In a for loop statement.
    3. In a foreach loop statement.
    4. In a using statement.
Lab 3: Using Implicit Typing


               Using implicit-typed variables.
               Using implicit typing with foreach context.
               Using implicit typing with custom classes
               and lists.
               Using Implicit Typing with multi-
               framework versions.
               Examining the types of the implicit-typed
               variables.
Extension Methods
                     Extension Methods Overview

  Extension Methods allows the developer to inject new
  methods to the existing compiled types without the need
  to re-write or override the current implementations.
  Extension Methods are natively supported in the VS
  2008 IDE.
  Defining Extension Methods:
   1.   Must be defined in separated static class.
   2.   Must be declared as static methods.
   3.   The first parameter modifier of the extension methods must be this
        keyword.
Lab 4: Using Extension Methods


              Extending types with extension methods.
              Consuming extension methods.
              Extending different .NET Framework built-
              in types.
Lambda Expressions
                      Lambda Expressions Overview

  Lambda expressions allows the developer to write
  functions in expression context instead of writing it the
  regular method body with a name.
  it consists of two sides separated by the lambda
  operator => “goes to”
   the left side specifies the parameters if any, and the
  right side holds the statement block or the expression.
  Lambda Expression Limitation:
   1.   It can be only used as a part of statement.
   2.   The lambda expression does not have a name.
   3.   Lambda expression cannot contain a goto, break, or continue
        statement whose target is outside the body.
Lab 5: Writing Expression Methods


              Writing lambda expressions
              Using the Lambda expressions.
              Understanding the different in writing
              expressions using delegates, anonymous
              methods, and lambda expressions.
Review




         In this module, you learned to:
            Examine the Auto Properties Feature
            Work with Initializers
            Use the Implicit Typing Feature
            Extending Existing Types
            Writing Lambda Expressions

Contenu connexe

Tendances

Tendances (20)

Sqlite3 databases
Sqlite3 databasesSqlite3 databases
Sqlite3 databases
 
Murach : HOW to work with controllers and routing
Murach : HOW to work with controllers and routingMurach : HOW to work with controllers and routing
Murach : HOW to work with controllers and routing
 
ASP.Net MVC 4 [Part - 2]
ASP.Net MVC 4 [Part - 2]ASP.Net MVC 4 [Part - 2]
ASP.Net MVC 4 [Part - 2]
 
MVC Training Part 1
MVC Training Part 1MVC Training Part 1
MVC Training Part 1
 
Schema-First API Design
Schema-First API DesignSchema-First API Design
Schema-First API Design
 
Google closure compiler
Google closure compilerGoogle closure compiler
Google closure compiler
 
Rspec
RspecRspec
Rspec
 
Angular 4 and TypeScript
Angular 4 and TypeScriptAngular 4 and TypeScript
Angular 4 and TypeScript
 
Mvc by asp.net development company in india - part 2
Mvc by asp.net development company in india  - part 2Mvc by asp.net development company in india  - part 2
Mvc by asp.net development company in india - part 2
 
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
Monorail presentation at WebDevelopersCommunity, Feb 1, 2009
 
Monorail Introduction
Monorail IntroductionMonorail Introduction
Monorail Introduction
 
Chapter 6 ppt
Chapter 6 pptChapter 6 ppt
Chapter 6 ppt
 
jQuery plugins & JSON
jQuery plugins & JSONjQuery plugins & JSON
jQuery plugins & JSON
 
Java Custom Annotations- Part1
Java Custom Annotations- Part1Java Custom Annotations- Part1
Java Custom Annotations- Part1
 
Part 4 Introduction to Gui with tkinter
Part 4 Introduction to Gui with tkinterPart 4 Introduction to Gui with tkinter
Part 4 Introduction to Gui with tkinter
 
Web API with ASP.NET MVC by Software development company in india
Web API with ASP.NET  MVC  by Software development company in indiaWeb API with ASP.NET  MVC  by Software development company in india
Web API with ASP.NET MVC by Software development company in india
 
OPEN STA
OPEN STAOPEN STA
OPEN STA
 
Les14
Les14Les14
Les14
 
Coded ui - lesson 5 - ui map
Coded ui - lesson 5 - ui mapCoded ui - lesson 5 - ui map
Coded ui - lesson 5 - ui map
 
AngularJs Style Guide
AngularJs Style GuideAngularJs Style Guide
AngularJs Style Guide
 

Similaire à Module 2: C# 3.0 Language Enhancements (Slides)

Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)Mohamed Saleh
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsSaurabh Narula
 
Templates and Exception Handling in C++
Templates and Exception Handling in C++Templates and Exception Handling in C++
Templates and Exception Handling in C++Nimrita Koul
 
C# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy todayC# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy todayAfonso Macedo
 
Apple’s New Swift Programming Language Takes Flight With New Enhancements And...
Apple’s New Swift Programming Language Takes Flight With New Enhancements And...Apple’s New Swift Programming Language Takes Flight With New Enhancements And...
Apple’s New Swift Programming Language Takes Flight With New Enhancements And...Azilen Technologies Pvt. Ltd.
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#Muhammad Younis
 
76829060 java-coding-conventions
76829060 java-coding-conventions76829060 java-coding-conventions
76829060 java-coding-conventionsslavicp
 
Perfomatix - iOS swift coding standards
Perfomatix - iOS swift coding standardsPerfomatix - iOS swift coding standards
Perfomatix - iOS swift coding standardsPerfomatix Solutions
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegantalenttransform
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programmingsmumbahelp
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programmingsmumbahelp
 

Similaire à Module 2: C# 3.0 Language Enhancements (Slides) (20)

Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)
 
csharp.docx
csharp.docxcsharp.docx
csharp.docx
 
Java
JavaJava
Java
 
Introduction of C++ By Pawan Thakur
Introduction of C++ By Pawan ThakurIntroduction of C++ By Pawan Thakur
Introduction of C++ By Pawan Thakur
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 Fundamentals
 
C# Unit 1 notes
C# Unit 1 notesC# Unit 1 notes
C# Unit 1 notes
 
Templates and Exception Handling in C++
Templates and Exception Handling in C++Templates and Exception Handling in C++
Templates and Exception Handling in C++
 
C# features
C# featuresC# features
C# features
 
C# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy todayC# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy today
 
Apple’s New Swift Programming Language Takes Flight With New Enhancements And...
Apple’s New Swift Programming Language Takes Flight With New Enhancements And...Apple’s New Swift Programming Language Takes Flight With New Enhancements And...
Apple’s New Swift Programming Language Takes Flight With New Enhancements And...
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#
 
C sharp
C sharpC sharp
C sharp
 
76829060 java-coding-conventions
76829060 java-coding-conventions76829060 java-coding-conventions
76829060 java-coding-conventions
 
Java annotations
Java annotationsJava annotations
Java annotations
 
Perfomatix - iOS swift coding standards
Perfomatix - iOS swift coding standardsPerfomatix - iOS swift coding standards
Perfomatix - iOS swift coding standards
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
C#ppt
C#pptC#ppt
C#ppt
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programming
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programming
 

Dernier

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Dernier (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

Module 2: C# 3.0 Language Enhancements (Slides)

  • 1. Visual Studio 2008 Training 3.5 RTM Mohamed Saleh MohamedSaleh@live.com www.jordev.net www.geeksconnected.com/mohamed
  • 2. Module 2: C# 3.0 Language Enhancements
  • 3. Overview Automate the process of creating properties Enhance the objects and collections using the Initializers Create implicitly typed local variables Extend existing types using Extension Methods Write the new lambda expressions Using the new features in multi-framework versions
  • 4. Automatically Implemented Properties Auto-Implemented Properties Overview Auto-Implemented Properties can handle the trivial implementation of getter and setter. The compiler will generate hidden backing fields with the implementation. This feature is related to the compiler and not the Framework Version or the Intermediate Language. The Auto-Implemented Properties can be implemented using the following syntax: public string Name { get; set; }
  • 5. Lab 1: Using Auto-Implemented Properties Using the Automatic Implemented Properties. Creating read-only and write-only properties. Using Automatic Implemented Properties with multi-framework versions. Examining the effects of the Automatic Implemented Properties on the generated intermediate language.
  • 6. Object and Collection Initializers Object Initializer Overview Object Initializers allows the developer to create the object instance and assign the initial values at the same time. The C# 2.0 way of initializing objects: Customer cst2 = new Customer(); cst2.ID = 2; cst2.Name = "Ayman Farouk"; cst2.Phone = "0799-987-980-98"; The C# 3.0 way of initializing objects: Customer cst3 = new Customer() { ID = 3, Name = "Osama Salam", Phone = "074-545-545-67" };
  • 7. Object and Collection Initializers Collection Initializers Overview The collection Initializers allows the developer to specify one or more elements Initializers when initializing any type that implements the System.Collections.Generic.IEnumerable<T>. Initializers Rules: 1. Object Initializers cannot include more than one member initializer for the same field or property. 2. The Object Initializers cannot refer to the newly created object it is initializing. 3. The Collection type must implements System.Collections.Generic.IEnumerable<T> in order to have initializers.
  • 8. Lab 2: Using Initializers Writing Object Initializer expressions. Writing Collection Initializer expressions. Using the nested object initializer. Using Initializers with multi-framework versions. Examining the generated initialization instructions in the intermediate language.
  • 9. Implicit Typing Implicit Typing Overview The new keyword var allows the C# compiler to infers the type of variables the compiler will determines the appropriate CLR type Var differ than variant keyword in VB6 and COM Implicit Typing Context: 1. Declaring variable at the method/property scope 2. In a for loop statement. 3. In a foreach loop statement. 4. In a using statement.
  • 10. Lab 3: Using Implicit Typing Using implicit-typed variables. Using implicit typing with foreach context. Using implicit typing with custom classes and lists. Using Implicit Typing with multi- framework versions. Examining the types of the implicit-typed variables.
  • 11. Extension Methods Extension Methods Overview Extension Methods allows the developer to inject new methods to the existing compiled types without the need to re-write or override the current implementations. Extension Methods are natively supported in the VS 2008 IDE. Defining Extension Methods: 1. Must be defined in separated static class. 2. Must be declared as static methods. 3. The first parameter modifier of the extension methods must be this keyword.
  • 12. Lab 4: Using Extension Methods Extending types with extension methods. Consuming extension methods. Extending different .NET Framework built- in types.
  • 13. Lambda Expressions Lambda Expressions Overview Lambda expressions allows the developer to write functions in expression context instead of writing it the regular method body with a name. it consists of two sides separated by the lambda operator => “goes to” the left side specifies the parameters if any, and the right side holds the statement block or the expression. Lambda Expression Limitation: 1. It can be only used as a part of statement. 2. The lambda expression does not have a name. 3. Lambda expression cannot contain a goto, break, or continue statement whose target is outside the body.
  • 14. Lab 5: Writing Expression Methods Writing lambda expressions Using the Lambda expressions. Understanding the different in writing expressions using delegates, anonymous methods, and lambda expressions.
  • 15. Review In this module, you learned to: Examine the Auto Properties Feature Work with Initializers Use the Implicit Typing Feature Extending Existing Types Writing Lambda Expressions