Download - Hidden Facts of .NET Language Gems
![Page 1: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/1.jpg)
Hidden facts of .NET 4.5 language gems
By Abhishek Sur
Website: www.abhisheksur.comEmail : [email protected]
![Page 2: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/2.jpg)
.NET Infrastructure
User InterfaceASP.NET
(Web Forms, MVC,
Dynamic Data)
Windows Presentation Foundation
Win Forms
Core
Services
Base Class Library
Common Language Runtime
Windows Workflow
Foundation
Windows Communicati
on Foundation
Data Access
Entity Framework
LINQ
ADO.NET
LINQ to SQL
Dynamic Async
Data Services (ODATA)
Generics
Cloud
Objects
![Page 3: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/3.jpg)
Agenda
Language GEMS
Iterators
Delegates
Events
Generics
Extension Methods
LINQ
Dynamic Types
Async
![Page 4: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/4.jpg)
What are loops ? A repetition of instructions ? A logical jump in code Or a representation of GoTo with a
condition…Types of Loops While do-while for goto ?... Lets take an example
![Page 5: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/5.jpg)
Iterators in .NET Represented by IEnumerable and
IEnumerator (which is not a collection) Ability to Pause – Resume a method. foreach is a syntactic sugar to iterate over
an iterator. Yield is used to generate an iterator
![Page 6: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/6.jpg)
![Page 7: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/7.jpg)
Iterators
Demo
![Page 8: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/8.jpg)
Delegates Delegates are special types Delegate points to Methods MulticastDelegates maintains an Invocation
List
Events Events are Wrappers to Delegates Cleaner pattern to handle Delegates Allows components to subscribe to it by
passing event handlers.
![Page 9: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/9.jpg)
Delegates & Events
Demo
![Page 10: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/10.jpg)
Generics Type as Template Constraint on Generic Types It can be applied on Types, Method,
Delegates etc. Variance is supportedExtension Methods Extend your predefined Types without
inheritance Uses ExtensionAttribute to identify extension
method.
![Page 11: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/11.jpg)
Generics & Extension Methods
Demo
![Page 12: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/12.jpg)
Anonymous Language Object
LINQ
Object can exist in language without name Cleaner codebase. Anonymous methods are used as Closures. We use delegate to refer anonymous
methods and var for types.
Search inside Managed objects Simple projection, selection, grouping, joins
and many more…
![Page 13: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/13.jpg)
Anonymous Types & LINQ
Demo
![Page 14: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/14.jpg)
Dynamic in .NET 4.0 CLR is mostly static type
◦ Compile time type checking DLR added dynamism to .NET
◦ Run time type checking Object – Static type, base class var – is ALSO static type, compiler inferred dynamic – Evaluation deferred Expandable objects
![Page 15: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/15.jpg)
Dynamic
Demo
![Page 16: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/16.jpg)
New Asynchronous Pattern
Contextual async & await pattern simplifies complex Threading model or existing pattern of coding
Async is not about Concurrency but rather it is truly asynchrony.
It can easily plugged in without changing the logic.
Compiler generates state machine to resume methods
![Page 17: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/17.jpg)
Async & Await
Demo
![Page 18: Hidden Facts of .NET Language Gems](https://reader033.vdocuments.net/reader033/viewer/2022051107/53fce4eb8d7f7288518b48db/html5/thumbnails/18.jpg)
Exposing the Compiler Ability to run compiler as a service. Syntax tree, Binder, Expression all are
available through code.