SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
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
 

Kürzlich hochgeladen (20)

Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
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
 

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