SlideShare a Scribd company logo
1 of 34
Download to read offline
Advanced features in C# 
1
Agenda 
Delegates & Events 
Anonymous Method 
Lambda Expressions 
Anonymous Types & Dynamic Type 
Extension Methods 
Reflection 
Attributes 
Q&A 
2
Delegates 
Historically, the Windows API made frequent use of C- style function pointers to create entities termed callback functions 
Using callbacks, programmers were able to configure one function to report back to (call back) another function in the application 
With this approach, Windows developers were able to handle button-clicking, mouse-moving, menu-selecting, and general bidirectional communications between two entities in memory 
3
Delegates 
Ideally, you should be able to configure callbacks to include additional type-safe information such as the number of (and types of) parameters and the return type (if any) of the method pointed to 
Sadly, this is not the case in traditional callback functions 
In the .NET Framework, callbacks are still possible, and this functionality is accomplished in a much safer and more object-oriented manner using delegates 
4
Delegates 
In essence, a delegate is a type-safe object that points to another method (or possibly a list of methods) in the application, which can be invoked at a later time. 
Specifically, a delegate maintains three important pieces of information 
The address of the method on which it makes calls 
The parameters(if any) of this method 
The return type(if any) of this method 
5
Delegates6
Delegates 
7
Delegates 
Recall that .NET delegates are type safe. Therefore, if you attempt to pass a delegate a method that does not match the pattern, you receive a compile-time error 
Given that the SampleDelegatecan point only to methods that take two integers and return an integer 
8
Delegates9
Delegates10
Delegates11
Delegates12
Delegates13
Events14
15
Agenda 
Delegates & Events 
Anonymous Method 
Lambda Expressions 
Anonymous Types & Dynamic Type 
Extension Methods 
Reflection 
Attributes 
Q&A 
16
Anonymous Method17
Anonymous Method18
Anonymous Method 
Strictly speaking, you are not required to receive the incoming arguments sent by a specific event. 
However, if you want to make use of the possible incoming arguments, you will need to specify the parameters prototyped by the delegate type 
Accessing Local Variables? (Page 450 –ebook) 
19
Agenda 
Delegates & Events 
Anonymous Method 
Lambda Expressions 
Anonymous Types & Dynamic Type 
Extension Methods 
Reflection 
Attributes 
Q&A 
20
Lambda Expressions 
C# supports the ability to handle events “inline” by assigning a block of code statements directly to an event using anonymous methods, rather than building a stand- alone method to be called by the underlying delegate 
Lambda expressions are nothing more than a very concise[ngắn-gọn]way to author anonymous methods and ultimately simplify how we work with the .NET delegate type 
21
Lambda Expressions 
22
Lambda Expressions 
ArgumentsToProcess=> StatementsToProcessThem 
List<int> evenNumbers= 
list.FindAll(i=> (i% 2) == 0); 
List<int> evenNumbers= list.FindAll(delegate (inti) 
{ 
return (i% 2) == 0; 
}); 
23
Agenda 
Delegates & Events 
Anonymous Method 
Lambda Expressions 
Anonymous Types & Dynamic Type 
Extension Methods 
Reflection 
Attributes 
Q&A 
24
Anonymous Types 
Whenever you need to define a class that is intended to be reused across projects and provides numerous bits of functionality through a set of methods, events, properties, and custom constructors, creating a new C# class is common practice 
However, there are other times when you would like to define a class simply to model a set of encapsulated (and somehow related) data points without any associated methods, events, or other specialized functionality 
Furthermore, what if this type is to be used only by a handful of methods in your program? 
25
Anonymous Types 
26
Anonymous Types 
All anonymous types are automatically derived from System.Objectand, therefore, support each of the members provided by this base class. Given this, we could invoke ToString(), GetHashCode(), Equals(),or GetType() 
The Semantics of Equality for Anonymous Types? 
27
Anonymous Types 
Anonymous Types Containing Anonymous Types 
28
Anonymous Types 
Anonymous type declarations should be used sparingly[hạn-chế], typically only when making use of the LINQ technology 
Anonymous types’ numerous limitations: 
You don’t control the name of the anonymous type 
Anonymous types always extend System.Object 
The fields and properties of an anonymous type are always read-only 
cannot support events, custom methods, custom operators, or custom overrides 
Anonymous types are always implicitly sealed. 
Anonymous types are always created using the default constructor. 
29
Dynamic Types 
You now have three ways to define data whose underlying type is not directly indicated in our code base 
30
Dynamic Types31
Dynamic Types 
Calling Members on Dynamically Declared Data 
32
Dynamic Types 
You will notseethe expected Visual Studio IntelliSense 
33
Dynamic Types 
Comparison between three ways to define data 
34

More Related Content

What's hot

Evolution of C# delegates
Evolution of C# delegatesEvolution of C# delegates
Evolution of C# delegatesmbaric
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event HandlingJussi Pohjolainen
 
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya UdagedaraLambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya UdagedaraJaliya Udagedara
 
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_iiNico Ludwig
 
03 oo with-c-sharp
03 oo with-c-sharp03 oo with-c-sharp
03 oo with-c-sharpNaved khan
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java Ahmad Idrees
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in javaGarik Kalashyan
 
Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminarGautam Roy
 
Jdk1.5 Features
Jdk1.5 FeaturesJdk1.5 Features
Jdk1.5 Featuresindia_mani
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in JavaGurpreet singh
 
A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrongJulien Wetterwald
 

What's hot (18)

Evolution of C# delegates
Evolution of C# delegatesEvolution of C# delegates
Evolution of C# delegates
 
C# Delegates
C# DelegatesC# Delegates
C# Delegates
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event Handling
 
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya UdagedaraLambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
 
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
 
03 oo with-c-sharp
03 oo with-c-sharp03 oo with-c-sharp
03 oo with-c-sharp
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
Interface
InterfaceInterface
Interface
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in java
 
Intake 37 4
Intake 37 4Intake 37 4
Intake 37 4
 
C#4.0 features
C#4.0 featuresC#4.0 features
C#4.0 features
 
Intake 37 2
Intake 37 2Intake 37 2
Intake 37 2
 
Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminar
 
C++
C++C++
C++
 
Jdk1.5 Features
Jdk1.5 FeaturesJdk1.5 Features
Jdk1.5 Features
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in Java
 
A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrong
 

Viewers also liked

C# .net lecture 1 in Hebrew
C# .net lecture 1 in HebrewC# .net lecture 1 in Hebrew
C# .net lecture 1 in HebrewDoron Raifman
 
CSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+ReflectionCSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+ReflectionMohammad Shaker
 
13 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_1913 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_19Niit Care
 
Spf Chapter4 Variables
Spf Chapter4 VariablesSpf Chapter4 Variables
Spf Chapter4 VariablesHock Leng PUAH
 
Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#Wekoslav Stefanovski
 
C# .net lecture 2 Objects 2
C# .net lecture 2 Objects 2C# .net lecture 2 Objects 2
C# .net lecture 2 Objects 2Doron Raifman
 
EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?Julie Lerman
 
A Tour of EF Core's (1.1) Most Interesting & Important Features
A Tour of EF Core's (1.1) Most Interesting & Important FeaturesA Tour of EF Core's (1.1) Most Interesting & Important Features
A Tour of EF Core's (1.1) Most Interesting & Important FeaturesJulie Lerman
 
Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#Fons Sonnemans
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsLukasz Lysik
 
.NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know....NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know...Dan Douglas
 
Dependency injection in asp.net core
Dependency injection in asp.net coreDependency injection in asp.net core
Dependency injection in asp.net coreBill Lin
 
Repository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir PoudelRepository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir PoudelSameer Poudel
 
ASP.NET MVC 4 - Routing Internals
ASP.NET MVC 4 - Routing InternalsASP.NET MVC 4 - Routing Internals
ASP.NET MVC 4 - Routing InternalsLukasz Lysik
 
Introduction the Repository Pattern
Introduction the Repository PatternIntroduction the Repository Pattern
Introduction the Repository PatternBill Lin
 
C# 6.0 - DotNetNotts
C# 6.0 - DotNetNottsC# 6.0 - DotNetNotts
C# 6.0 - DotNetNottscitizenmatt
 
Repository and Unit Of Work Design Patterns
Repository and Unit Of Work Design PatternsRepository and Unit Of Work Design Patterns
Repository and Unit Of Work Design PatternsHatim Hakeel
 

Viewers also liked (20)

C# .net lecture 1 in Hebrew
C# .net lecture 1 in HebrewC# .net lecture 1 in Hebrew
C# .net lecture 1 in Hebrew
 
CSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+ReflectionCSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+Reflection
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
 
Study research in April
Study research in AprilStudy research in April
Study research in April
 
13 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_1913 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_19
 
Spf Chapter4 Variables
Spf Chapter4 VariablesSpf Chapter4 Variables
Spf Chapter4 Variables
 
Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#
 
C# .net lecture 2 Objects 2
C# .net lecture 2 Objects 2C# .net lecture 2 Objects 2
C# .net lecture 2 Objects 2
 
EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?
 
A Tour of EF Core's (1.1) Most Interesting & Important Features
A Tour of EF Core's (1.1) Most Interesting & Important FeaturesA Tour of EF Core's (1.1) Most Interesting & Important Features
A Tour of EF Core's (1.1) Most Interesting & Important Features
 
Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline Internals
 
.NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know....NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know...
 
Dependency injection in asp.net core
Dependency injection in asp.net coreDependency injection in asp.net core
Dependency injection in asp.net core
 
Repository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir PoudelRepository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir Poudel
 
ASP.NET MVC 4 - Routing Internals
ASP.NET MVC 4 - Routing InternalsASP.NET MVC 4 - Routing Internals
ASP.NET MVC 4 - Routing Internals
 
Reflection in C#
Reflection in C#Reflection in C#
Reflection in C#
 
Introduction the Repository Pattern
Introduction the Repository PatternIntroduction the Repository Pattern
Introduction the Repository Pattern
 
C# 6.0 - DotNetNotts
C# 6.0 - DotNetNottsC# 6.0 - DotNetNotts
C# 6.0 - DotNetNotts
 
Repository and Unit Of Work Design Patterns
Repository and Unit Of Work Design PatternsRepository and Unit Of Work Design Patterns
Repository and Unit Of Work Design Patterns
 

Similar to Day02 01 Advance Feature in C# DH TDT

tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...Anil Sharma
 
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Featurestechfreak
 
Can't Dance The Lambda
Can't Dance The LambdaCan't Dance The Lambda
Can't Dance The LambdaTogakangaroo
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelMichael Heron
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp PresentationVishwa Mohan
 
Lessons Learned from Building Machine Learning Software at Netflix
Lessons Learned from Building Machine Learning Software at NetflixLessons Learned from Building Machine Learning Software at Netflix
Lessons Learned from Building Machine Learning Software at NetflixJustin Basilico
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#SyedUmairAli9
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsakreyi
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
C# advanced topics and future - C#5
C# advanced topics and future - C#5C# advanced topics and future - C#5
C# advanced topics and future - C#5Peter Gfader
 
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
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeNaresh Jain
 

Similar to Day02 01 Advance Feature in C# DH TDT (20)

tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
 
Cs30 New
Cs30 NewCs30 New
Cs30 New
 
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
 
Can't Dance The Lambda
Can't Dance The LambdaCan't Dance The Lambda
Can't Dance The Lambda
 
Essential language features
Essential language featuresEssential language features
Essential language features
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event Model
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Lessons Learned from Building Machine Learning Software at Netflix
Lessons Learned from Building Machine Learning Software at NetflixLessons Learned from Building Machine Learning Software at Netflix
Lessons Learned from Building Machine Learning Software at Netflix
 
C#.net Evolution part 1
C#.net Evolution part 1C#.net Evolution part 1
C#.net Evolution part 1
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
C sharp
C sharpC sharp
C sharp
 
csharp.docx
csharp.docxcsharp.docx
csharp.docx
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Classes1
Classes1Classes1
Classes1
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
C# advanced topics and future - C#5
C# advanced topics and future - C#5C# advanced topics and future - C#5
C# advanced topics and future - C#5
 
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
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 

More from Nguyen Patrick

Tai lieu on thi chung chi ibm
Tai lieu on thi chung chi ibmTai lieu on thi chung chi ibm
Tai lieu on thi chung chi ibmNguyen Patrick
 
Giao trinh phan tich thiet ke he thong thong tin
Giao trinh phan tich thiet ke he thong thong tinGiao trinh phan tich thiet ke he thong thong tin
Giao trinh phan tich thiet ke he thong thong tinNguyen Patrick
 
Ap dung hoc tin chi tren the gioi va viet nam
Ap dung hoc tin chi tren the gioi va viet namAp dung hoc tin chi tren the gioi va viet nam
Ap dung hoc tin chi tren the gioi va viet namNguyen Patrick
 

More from Nguyen Patrick (6)

E commerce landscape
E commerce landscapeE commerce landscape
E commerce landscape
 
Short stories
Short storiesShort stories
Short stories
 
Tai lieu on thi chung chi ibm
Tai lieu on thi chung chi ibmTai lieu on thi chung chi ibm
Tai lieu on thi chung chi ibm
 
Giao trinh phan tich thiet ke he thong thong tin
Giao trinh phan tich thiet ke he thong thong tinGiao trinh phan tich thiet ke he thong thong tin
Giao trinh phan tich thiet ke he thong thong tin
 
Ap dung hoc tin chi tren the gioi va viet nam
Ap dung hoc tin chi tren the gioi va viet namAp dung hoc tin chi tren the gioi va viet nam
Ap dung hoc tin chi tren the gioi va viet nam
 
Hoc adobe ilusstrator
Hoc adobe ilusstratorHoc adobe ilusstrator
Hoc adobe ilusstrator
 

Recently uploaded

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

Day02 01 Advance Feature in C# DH TDT

  • 2. Agenda Delegates & Events Anonymous Method Lambda Expressions Anonymous Types & Dynamic Type Extension Methods Reflection Attributes Q&A 2
  • 3. Delegates Historically, the Windows API made frequent use of C- style function pointers to create entities termed callback functions Using callbacks, programmers were able to configure one function to report back to (call back) another function in the application With this approach, Windows developers were able to handle button-clicking, mouse-moving, menu-selecting, and general bidirectional communications between two entities in memory 3
  • 4. Delegates Ideally, you should be able to configure callbacks to include additional type-safe information such as the number of (and types of) parameters and the return type (if any) of the method pointed to Sadly, this is not the case in traditional callback functions In the .NET Framework, callbacks are still possible, and this functionality is accomplished in a much safer and more object-oriented manner using delegates 4
  • 5. Delegates In essence, a delegate is a type-safe object that points to another method (or possibly a list of methods) in the application, which can be invoked at a later time. Specifically, a delegate maintains three important pieces of information The address of the method on which it makes calls The parameters(if any) of this method The return type(if any) of this method 5
  • 8. Delegates Recall that .NET delegates are type safe. Therefore, if you attempt to pass a delegate a method that does not match the pattern, you receive a compile-time error Given that the SampleDelegatecan point only to methods that take two integers and return an integer 8
  • 15. 15
  • 16. Agenda Delegates & Events Anonymous Method Lambda Expressions Anonymous Types & Dynamic Type Extension Methods Reflection Attributes Q&A 16
  • 19. Anonymous Method Strictly speaking, you are not required to receive the incoming arguments sent by a specific event. However, if you want to make use of the possible incoming arguments, you will need to specify the parameters prototyped by the delegate type Accessing Local Variables? (Page 450 –ebook) 19
  • 20. Agenda Delegates & Events Anonymous Method Lambda Expressions Anonymous Types & Dynamic Type Extension Methods Reflection Attributes Q&A 20
  • 21. Lambda Expressions C# supports the ability to handle events “inline” by assigning a block of code statements directly to an event using anonymous methods, rather than building a stand- alone method to be called by the underlying delegate Lambda expressions are nothing more than a very concise[ngắn-gọn]way to author anonymous methods and ultimately simplify how we work with the .NET delegate type 21
  • 23. Lambda Expressions ArgumentsToProcess=> StatementsToProcessThem List<int> evenNumbers= list.FindAll(i=> (i% 2) == 0); List<int> evenNumbers= list.FindAll(delegate (inti) { return (i% 2) == 0; }); 23
  • 24. Agenda Delegates & Events Anonymous Method Lambda Expressions Anonymous Types & Dynamic Type Extension Methods Reflection Attributes Q&A 24
  • 25. Anonymous Types Whenever you need to define a class that is intended to be reused across projects and provides numerous bits of functionality through a set of methods, events, properties, and custom constructors, creating a new C# class is common practice However, there are other times when you would like to define a class simply to model a set of encapsulated (and somehow related) data points without any associated methods, events, or other specialized functionality Furthermore, what if this type is to be used only by a handful of methods in your program? 25
  • 27. Anonymous Types All anonymous types are automatically derived from System.Objectand, therefore, support each of the members provided by this base class. Given this, we could invoke ToString(), GetHashCode(), Equals(),or GetType() The Semantics of Equality for Anonymous Types? 27
  • 28. Anonymous Types Anonymous Types Containing Anonymous Types 28
  • 29. Anonymous Types Anonymous type declarations should be used sparingly[hạn-chế], typically only when making use of the LINQ technology Anonymous types’ numerous limitations: You don’t control the name of the anonymous type Anonymous types always extend System.Object The fields and properties of an anonymous type are always read-only cannot support events, custom methods, custom operators, or custom overrides Anonymous types are always implicitly sealed. Anonymous types are always created using the default constructor. 29
  • 30. Dynamic Types You now have three ways to define data whose underlying type is not directly indicated in our code base 30
  • 32. Dynamic Types Calling Members on Dynamically Declared Data 32
  • 33. Dynamic Types You will notseethe expected Visual Studio IntelliSense 33
  • 34. Dynamic Types Comparison between three ways to define data 34