This document summarizes features introduced in C# 2, including delegates, anonymous methods, and delegate variance. Delegates allow passing methods as arguments and are used for events. C# 2 simplified delegate instantiation and introduced anonymous methods, which define inline delegate code without a named method. Underneath, anonymous methods use compiler-generated classes to capture outer scope variables. Delegate variance allows compatibility between delegate types and instances if their return and parameter types are related through inheritance.
Managing Binary Compatibility in Scala (Scala Lift Off 2011)mircodotta
Slides of my Scala Lift Off 2011 talk. The content of the presentation is mostly similar to the one presented at Scala Days 2011, with a few additions. Particularly, lazy values are discussed.
Core Java Programming Language (JSE) : Chapter III - Identifiers, Keywords, ...WebStackAcademy
An identifier is a name that is used for the identification purpose. It can either be a class name, method name, variable name, or label name. While creating identifier one must be aware of some rules that has to be followed strictly. Here are the things that can be included while creating java identifiers.
Keywords are predefined, reserved words used in Java programming that have special meanings to the compiler. For example:
int score;
Here, int is a keyword. It indicates that the variable score is of integer type (32-bit signed two's complement integer).
You cannot use keywords like int, for, class etc as variable name (or identifiers) as they are part of the Java programming language syntax. Here's the complete list of all keywords in Java programming.
The eight primitive data types in Java are:
boolean, the type whose values are either true or false
char, the character type whose values are 16-bit Unicode characters
the arithmetic types:
the integral types:
byte
short
int
long
the floating-point types:
float
double
Generic programming is a style of computer programming in which algorithms are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provided as parameters.
Generics are a facility of generic programming that were added to the Java programming language in 2004 within version J2SE 5.0. They were designed to extend Java's type system to allow “a type or method to operate on objects of various types while providing compile-time type safety”
The Java collections framework supports generics to specify the type of objects stored in a collection instance.
This presentation introduces some advanced concepts of generics in Java. These slides introduce the following concepts:
- Generic classes and methods
- Type variable bounds
- Type erasure process
- Generics and inheritance
- Wildcard types
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the main features of Scala, an object oriented and functional programming language. The main focus of the slides is to show how the language implements natively some of the patterns and best practices that are no present in other programming languages, such as Java, C++ and so on.
In detail, the presentation spans these concepts:
- Language's main syntax
- Classes, abstract classes, objects and traits (mixin)
- The Option class
- An introduction to generics
- Implicit classes
- Functions
- Recursion (simple and tail)
- Currying
- Call by value / name
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Managing Binary Compatibility in Scala (Scala Lift Off 2011)mircodotta
Slides of my Scala Lift Off 2011 talk. The content of the presentation is mostly similar to the one presented at Scala Days 2011, with a few additions. Particularly, lazy values are discussed.
Core Java Programming Language (JSE) : Chapter III - Identifiers, Keywords, ...WebStackAcademy
An identifier is a name that is used for the identification purpose. It can either be a class name, method name, variable name, or label name. While creating identifier one must be aware of some rules that has to be followed strictly. Here are the things that can be included while creating java identifiers.
Keywords are predefined, reserved words used in Java programming that have special meanings to the compiler. For example:
int score;
Here, int is a keyword. It indicates that the variable score is of integer type (32-bit signed two's complement integer).
You cannot use keywords like int, for, class etc as variable name (or identifiers) as they are part of the Java programming language syntax. Here's the complete list of all keywords in Java programming.
The eight primitive data types in Java are:
boolean, the type whose values are either true or false
char, the character type whose values are 16-bit Unicode characters
the arithmetic types:
the integral types:
byte
short
int
long
the floating-point types:
float
double
Generic programming is a style of computer programming in which algorithms are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provided as parameters.
Generics are a facility of generic programming that were added to the Java programming language in 2004 within version J2SE 5.0. They were designed to extend Java's type system to allow “a type or method to operate on objects of various types while providing compile-time type safety”
The Java collections framework supports generics to specify the type of objects stored in a collection instance.
This presentation introduces some advanced concepts of generics in Java. These slides introduce the following concepts:
- Generic classes and methods
- Type variable bounds
- Type erasure process
- Generics and inheritance
- Wildcard types
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
This presentation introduces the main features of Scala, an object oriented and functional programming language. The main focus of the slides is to show how the language implements natively some of the patterns and best practices that are no present in other programming languages, such as Java, C++ and so on.
In detail, the presentation spans these concepts:
- Language's main syntax
- Classes, abstract classes, objects and traits (mixin)
- The Option class
- An introduction to generics
- Implicit classes
- Functions
- Recursion (simple and tail)
- Currying
- Call by value / name
The presentation is took from the Software Engineering course I run in the bachelor-level informatics curriculum at the University of Padova.
Core Java Developer Certification helps demonstrate an individual's overall comprehension and expertise of Java programming language. VSkills Core Java Developer Certification holders have more than a working familiarity with Java programs—they are technically skilled to take advantage of the breadth of features efficiently and effectively.
http://www.vskills.in/certification/Certified-Core-Java-Developer
An introduction to some advanced language features of the object-oriented programming language Ruby, part of a full lecture on Programming Paradigms at UCL university in Belgium, focussing on the programming languages Smalltalk, Ruby and Java, with reflection and meta programming as underlying theme. This lecture looks into the Ruby features of higher-order programming (lambdas), singleton methods, mixin modules, reflection and metaprogramming.
All 'classic' 23 GOF Design Patterns, illustrated by Nelleke Verhoeff (Red Cheeks Factory). Trying to show the essence of each Design Pattern, with some examples from PHP.
Second version of my Design Patterns presentation. This presentation was held February 13, 2014 at the 010PHP meeting in Rotterdam. Presentation was in Dutch.
Managing Binary Compatibility in Scala (Scala Days 2011)mircodotta
The following is the abstract submitted for my Scala Days 2011 talk:
Binary compatibility is not a topic specific to the Scala language, but rather a concern for all languages targeting the JVM, Java included. Scala shares with Java many sources of potential binary incompatibilities, however, because of Scala greater expressiveness, Scala code has unique sources of incompatibility.
The Scala programming language offers several language constructs that do not have an equivalent in Java and are not natively supported by the JVM. Because of this, the Scala compiler (scalac) transforms these constructs into lower-lever, Java compatible, patterns that can be then easily translated into bytecode. Good examples of such high-level Scala constructs are traits, for mixin-based inheritance, and functions as first data citizens.
During this presentation we will review the main sources of binary incompatibility for the Scala language, providing you with useful insights about how you should evolve your codebase to avoid binary incompatibilities. Furthermore, we will show a tool, the Migration Manager, that can be used to automatically diagnose binary incompatibilities between two versions of a same library.
Swift is the latest new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. This presentation is all about Closures, Structures, Enum, Memory Management & Extensions.
Core Java Developer Certification helps demonstrate an individual's overall comprehension and expertise of Java programming language. VSkills Core Java Developer Certification holders have more than a working familiarity with Java programs—they are technically skilled to take advantage of the breadth of features efficiently and effectively.
http://www.vskills.in/certification/Certified-Core-Java-Developer
An introduction to some advanced language features of the object-oriented programming language Ruby, part of a full lecture on Programming Paradigms at UCL university in Belgium, focussing on the programming languages Smalltalk, Ruby and Java, with reflection and meta programming as underlying theme. This lecture looks into the Ruby features of higher-order programming (lambdas), singleton methods, mixin modules, reflection and metaprogramming.
All 'classic' 23 GOF Design Patterns, illustrated by Nelleke Verhoeff (Red Cheeks Factory). Trying to show the essence of each Design Pattern, with some examples from PHP.
Second version of my Design Patterns presentation. This presentation was held February 13, 2014 at the 010PHP meeting in Rotterdam. Presentation was in Dutch.
Managing Binary Compatibility in Scala (Scala Days 2011)mircodotta
The following is the abstract submitted for my Scala Days 2011 talk:
Binary compatibility is not a topic specific to the Scala language, but rather a concern for all languages targeting the JVM, Java included. Scala shares with Java many sources of potential binary incompatibilities, however, because of Scala greater expressiveness, Scala code has unique sources of incompatibility.
The Scala programming language offers several language constructs that do not have an equivalent in Java and are not natively supported by the JVM. Because of this, the Scala compiler (scalac) transforms these constructs into lower-lever, Java compatible, patterns that can be then easily translated into bytecode. Good examples of such high-level Scala constructs are traits, for mixin-based inheritance, and functions as first data citizens.
During this presentation we will review the main sources of binary incompatibility for the Scala language, providing you with useful insights about how you should evolve your codebase to avoid binary incompatibilities. Furthermore, we will show a tool, the Migration Manager, that can be used to automatically diagnose binary incompatibilities between two versions of a same library.
Swift is the latest new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. This presentation is all about Closures, Structures, Enum, Memory Management & Extensions.
Gestionando la relación con los clientes... más allá del contactoAMETIC
Presentación a cargo de Alfredo Redondo Iglesias, CEO de Altitude Software, en el 28º Encuentro de Telecomunicaciones y Economía Digital organizado por AMETIC y Fundación Telefónica en el marco de los cursos de verano de la UIMP del 1 al 4 de septiembre de 2014
Ascension Parish Home Sales and Prices June 2013 vs June 2014 Prairieville Go...Bill Cobb, Appraiser
Ascension Parish Home Sales and Prices June 2013 vs June 2014 Prairieville Gonzales Geismar
Published by Bill Cobb, Greater Baton Rouge's Home Appraiser
225-293-1500
http://www.ascensionrealestateappraisers.com
GREATER BATON ROUGE REAL ESTATE DATA NOTE:
Based on information from Greater Baton Rouge Association of REALTORS®\MLS for period June 2013 to June 2014, extracted on 07/14/2014.
Book@9212612173 Jaypee Greens The OrchardsCandry Johnson
Jaypee The Orchards, luxurious Golf apartments will redefine your lifestyle with its meticulously designed exclusive architecture giving the residents endless views of 18 hole Golf course. As the name suggests, the apartments would be amidst beautiful Orchards of different varieties giving you a refreshing sight that calms your mind and soothes your senses.
(7) c sharp introduction_advanvced_features_part_iiNico Ludwig
This presentation comes with many additional notes (pdf): http://de.slideshare.net/nicolayludwig/7-c-sharp-introductionadvanvcedfeaturespartii-38640489
Check out these exercises: http://de.slideshare.net/nicolayludwig/6-7-c-sharp-introductionadvancedfeaturespartipartiiexercises
- Object-based and generic Collections
- Delegates and Events
- Custom Attributes
- Reflection
Top 20 c# interview Question and answersw3asp dotnet
This presentation contains interview question and answers . www.w3asp.net provide you the information, knowledge, job, practices and tranings regarding asp.net.
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
Discussing Design Patterns and OOP popularity,
Multithreading and OOP,
Functional Design for Multithreaded programming
and how Multithreading does not mean always concurency but multicore paralelism.
Similar to Review of c_sharp2_features_part_ii (20)
Von Gleichungen zu Funktionen
Überblick über ganzrationale Funktionen
Koordinatensysteme für Graphen ganzrationaler Funktionen mit Excels Liniendiagrammen erstellen
Einfache Analyse ganzrationaler Funktionen anhand deren Graphen
Von linearen zu quadratischen Gleichungssystemen
Verschiedene Möglichkeiten quadratische Gleichungssysteme grafisch zu lösen
Koordinatensysteme für quadratische Graphen mit Excels Liniendiagrammen erstellen und Gleichungen damit grafisch lösen
Grafische Interpretation der Lösungen von Normalparabel-Gerade Kombinationen
Diagramme
Einführung linearer Gleichungssysteme mit zwei Unbekannten
Rechnerische und grafische Lösung linearer Gleichungssysteme
Wertetabellen mit Excel erstellen
Koordinatensysteme und lineare Graphen mit Excels Liniendiagrammen erstellen und Gleichungen damit grafisch lösen
Mit großen Tabellen arbeiten
Sortieren und Filtern
Objekte einfügen
Formeln und rechnen mit Excel, insbesondere Zahlen und Textbearbeitung
Relative und absolute Zellbezüge
Funktionen: SUMME(), ANZAHL(), MIN(), MAX(), MITTELWERT(), JETZT(), HEUTE(), ZUFALLSZAHL(), PI() und SUMMEWENN()
Mathematische Probleme in Tabellenform
Geschichtliche Entwicklung
Grundlegende Konzepte und Begriffe in Excel
Selektion, Dateneingabe und Datentypen
Zellformatierung und Inhaltsformatierung
- Vector- and Raster-based Graphics
-- Idea behind Vector- and Raster-based Graphics
-- Crispness
-- Overview of Raster-based Drawing APIs
- Platform independent Graphics and GUIs in the Web Browser
-- Bare HTML Pages
-- Plugins and Problems
-- From rich Content to HTML 5
- Drawing with HTML 5 Canvas
-- Continuous, Event driven and free Drawing
-- Basic Drawing "How does Drawing work with JavaScript?"
-- Interaction with Controls
- Vector- and Raster-based Graphics
-- Idea behind Vector- and Raster-based Graphics
-- Crispness
-- Overview of Raster-based Drawing APIs
- Platform independent Graphics and GUIs in the Web Browser
-- Bare HTML Pages
-- Plugins and Problems
-- From rich Content to HTML 5
- Drawing with HTML 5 Canvas
-- Continuous, Event driven and free Drawing
-- Basic Drawing "How does Drawing work with JavaScript?"
-- Interaction with Controls
- Wires and Bulbs
- Batch Processing
- Terminal and Mainframe
- From the Command-Line to Killer Applications
- Vector Displays and Raster Displays
- Color Displays
- The Mouse and the Takeoff of Interactivity
- The Desktop Metaphor
- Wires and Bulbs
- Batch Processing
- Terminal and Mainframe
- From the Command-Line to Killer Applications
- Vector Displays and Raster Displays
- Color Displays
- The Mouse and the Takeoff of Interactivity
- The Desktop Metaphor
1. 1
Review of C#2 Features – Part II
Nico Ludwig (@ersatzteilchen)
2. 2
TOC
● Review of C#2 Features – Part II
– Delegates, Methods and Method Groups
– Anonymous Methods
– Variance of Delegates
● Sources:
– Jeffrey Richter, Applied Microsoft .Net Framework Programming
– Jon Skeet, CSharp in Depth
3. 3
Delegates in C#1
<DelegateExamples>
WPresents how we work with Delegates in C#1.
4. 4
Delegates, Methods and Method Groups
● Delegates are types: A Delegate describes a type of a method.
– Any Delegate eventually derives from Delegate (MulticastDelegate).
● A method matching the Delegate can be called by an instance of that Delegate.
– Similar to function pointers in C/C++.
– (Multicasting (i.e. a delegate as a collection of methods (an invocation list)) is an extra feature of Delegates.)
● All overloads of a method visible in the current context are calledmethod group.
– The method group is a kind of symbolic name of a method.
● Most important uses of Delegates:
– Working with events (e.g. in UIs Delegate instances are used as callbacks).
– Passing around code to be executed in a different thread (Control.Invoke(Delegate), new Thread(ThreadStart),
ThreadPool.QueueUserWorkItem(WaitCallback) etc.).
● A method group is the set of all methods found by
a member lookup of a certain method name in a
certain context. E.g. all overloads of a method
being effectively present due to inheritance from
multiple types are part of that method's method
group.
5. 5
Simplified Delegate Instantiation in Action
<DelegateExamples>
WPresents simplified Delegate Instantiation in C#2.
6. 6
Simplified Delegate Instantiation
// New in C#2: create a Delegate instance from a method group:
aDelegateInstance = Foo;
// Creating a Delegate instance in C#1:
aDelegateInstance = new AcceptString(Foo);
● In C#2 it's allowed to instantiate a Delegate from a method group item directly.
– I.e. the immediate step to create a Delegate instance can be skipped.
delegate void EventHandler(object sender, EventArgs e); // The Delegate.
private void MyForm_Load(object sender, EventArgs e) { /* pass */ } // An event handler.
// Advise an event handler in C#1:
Load += new EventHandler(MyForm_Load);
// New in C#2: advise event handler from a method group:
Load += MyForm_Load;
● (Perspective: an Event/delegate object is just a collection of methods in .Net)
● Event handlers can also be advised from a method group in C#2.
– I.e. method groups can be chained to combine them to an invocation list directly.
● The definition of a Delegate type looks a little bit
like a typedef in C/C++.
7. 7
WFirst Example with Anonymous Methods
<DelegateExamples>
First example with anonymous methods.
8. From Simplified Delegate Instantiation to Anonymous Methods
8
// Initialization of a Delegate instance the conventional way:
AcceptString printToConsole = new AcceptString(PrintSomethingToConsole);
// New in C#2: Initialization of a Delegate instance with an anonymous method:
AcceptString printToConsole = delegate(string s)
{
Debug.WriteLine(s);
};
● Anonymous methods: Delegate instance code can be inlined completely.
– I.e. a method can be defined as an anonymous block of code.
– Similar concepts: Closure (Groovy, Python, ECMAScript), Block (Smalltalk, Ruby, Objective-C)
– An anonymous method can access outer local contexts/variables (i.e. closures)!
– The signature of the anonymous method is checked against the Delegate.
– This is an outstanding feature in C#2!
● The syntax is similar to ECMAScript's/JavaScript's
function literals (var f = function(x) { return x * x; }).
- So in other words, JavaScript has this feature for
ages.
10. 10
More on anonymous Methods
● For each anonymous method the compiler will generate an ordinary method.
● For anonymous methods the compiler may (MS specific) generate a class.
– Classes are needed to put closures into effect with locals.
● Such a class has a method containing the anonymous method's code.
● Such a class has fields to hold/capture references of the local context respectively.
● If instance members are accessed in the anonymous method, a field to hold this is added.
– No class needs to be generated, if no outer locals are being referenced.
● Then the anonymous method's code is held by an ordinary class or instance method.
● Attention: The lifetime of captured locals is extended! Captured referencescan't be garbage collected (gc'd), as long as
the Delegate instance wasn't gc'd!
– An anon. method (Delegate instance) has a lexical binding of the enclosing scope's locals and the this reference! -> You can
access these bindings in the anon. method.
– If you use these bindings in an anon. method, the bound objects can only be gc'd, if the Delegate instance expressed by the anon.
method is gc'd.
● From within anonymous methods you can refer the enclosing
scope's locals and also the this reference in instance methods
of reference types. So in anonymous methods locals and the
this reference are bound lexically.
● MS specific: The local variables will be captured as instance
variables of a compiler generated "capture-class" that also
holds the anonymous method as instance method. An
instance of this "capture-class" is created locally where the
anonymous method was written and provides the mentioned
instance method as Delegate instance. If this is captured, a
field to hold it will be created as well, and this will also be the
Target of the Delegate instance (in other cases it is null).
When the instance of the "capture-class" is gc'd, the captured
variables (as instance variables) can be gc'd as well.
● Attention, there is a source of memory leaks: Captured
references can't be gc'd, as long as the Delegate instance (or
the "capture-class") wasn't gc'd! And the Delegate instance's
Target object can not be gc'd as long as the object, to which
the Delegate instance was advised as event handler wasn't
gc'd!
● Another problem: during run time "names" of anonymous
methods are obfuscated to unspeakable compiler-generated
symbols. These symbols are then visible in stack-traces and
in reverse-engineered code.
● A different way to understand this: anonymous methods a
esp. suitable for methods that are not reusable
11. 11
Everyday use of anonymous Methods
<DelegateExamples>
Everyday use of anonymous Methods.
12. 12
Transporting Code with Delegates
● Another perception of Delegate instances: a way to pass code to methods.
● Therefor .Net 2 provides two generic multipurpose Delegate types:
delegate void Action<T>(T item); // A Delegate describing methods acting on item.
delegate bool Predicate<T>(T item); // A Delegate describing methods that check a
● On the opposite some types (e.g. List<T>) provide methods that make use of those new Delegate types e.g.:
● These new tools provide ways to get rid of explicitly writing loops.
– But this is just the beginning of the "transporting code" story, in C#3 this concept has been developed to the next level to work w/
any enumerable object: with LINQ.
// predicate on item.
public void List<T>.ForEach(Action<T> action); // Do action for each item.
public bool List<T>.RemoveAll(Predicate<T> match); // Remove all items that
// match the passed Predicate.
● In .Net 1.x most developers used Delegates
(types and instances) for two purposes:
● Handling events (e.g. in UIs).
● Passing around code to be executed in a
different thread (e.g. by Control.Invoke, or by
Thread(ThreadStart), or by
ThreadPool.QueueUserWorkItem(WaitCallback)
).
13. 13
Delegate Variance
<DelegateExamples>
These examples show Delegate co- and contravariance.
14. 14
Delegates are variant in C#2
● Variance expresses compatibility of Delegate instances to a Delegate type, if:
– the return types of Delegate instance and type are related: as covariance; and if
– the parameter types of Delegate instance and type are related: as contravariance.
● Covariant return type:
– The instance's return type can be more derived than the Delegate type's.
– I.e. a Delegate instance may "deliver more" than the Delegate type.
● Contravariant parameter type:
– An instance's parameter types can be less derived than the Delegate type's.
– I.e. a Delegate instance may "require less" than the Delegate type.
– Fine for event handlers: you get more derived EventArgs and deal with the base type.
● (This has nothing to do with generic variance available in C#4/.Net 4!)
● In the development phase of the CLR 2, this
feature was called "relaxed Delegates".