IT College 2016, Andres käver

Slides:



Advertisements
Similar presentations
Copyright © 2012 Pearson Education, Inc. Chapter 9 Delegates and Events.
Advertisements

George Fairfield / Westchester Code Camp 4 (2010)
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Lecture 3: Topics If-then-else Operator precedence While loops Static methods Recursion.
ECE122 Feb Introduction to Class and Object Java is an object-oriented language. Java’s view of the world is a collection of objects and their.
Java: How to Program Methods Summary Yingcai Xiao.
Delegates and Events Tom Roeder CS fa. Motivation – Function Pointers Treat functions as first-class objects eg. Scheme: (map myfunc somelist)
Interfaces besides classes, Java recognizes another type, an interface interface is used to completely shield off all implementation from the programmer.
PARALLEL PROGRAMMING ABSTRACTIONS 6/16/2010 Parallel Programming Abstractions 1.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
C# vs. C++ What's Different & What's New. An example C# public sometype myfn { get; set; } C++ public: sometype myfn { sometype get (); void set (sometype.
COMP More About Classes Yi Hong May 22, 2015.
Extension Methods Programming in C# Extension Methods CSE Prof. Roger Crawfis.
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
Delegates and lambda functions Jim Warren, COMPSCI 280 S Enterprise Software Development.
Local Variables A local variable is a variable that is declared within a method declaration. Local variables are accessible only from the method in which.
CIS 3301 C# Lesson 5 Methods. CIS 3302 Objectives Understand the structure of a method. Know the difference between static and instance methods. Learn.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Class Example - Rationals Rational numbers are represented by the ratio of two integers, a numerator and a denominator, e.g., 2/3. This is opposed to irrational.
ECE122 Feb. 22, Any question on Vehicle sample code?
RECITATION 4. Classes public class Student { } Data Members public class Student { private String name; public String id; }
SE-1010 Dr. Mark L. Hornick 1 Java Programming Basics.
Lambda Expressions Version 1.0
FUNCTIONS IN C++. DEFINITION OF A FUNCTION A function is a group of statements that together perform a task. Every C++ program has at least one function,
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
CSI 3125, Preliminaries, page 1 Compiling the Program.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
FEN 2014UCN Teknologi/act2learn1 Higher order functions Observer Pattern Delegates Events Visitor Pattern Lambdas and closures Lambdas in libraries.
Satisfy Your Technical Curiosity C# 3.0 Raj Pai Group Program Manager Microsoft Corporation
From C++ to C# Part 5. Enums Similar to C++ Similar to C++ Read up section 1.10 of Spec. Read up section 1.10 of Spec.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
IAP C# 2011 Lecture 2: Delegates, Lambdas, LINQ Geza Kovacs.
Support standard JavaScript code with static typing Encapsulation through classes and modules Support for constructors, properties and.
Department of Electronic & Electrical Engineering Functions Parameters Arguments Pointers/dereference & * Scope Global/Local Storage Static/Automatic.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
V 1.0 OE-NIK HP 1 Advanced Programming Delegates, Events.
APS105 Functions (and Pointers) 1. Modularity –Break a program into manageable parts (modules) –Modules interoperate with each other Benefits of modularity:
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Unit 2. Constructors It initializes an object when it is created. It has same as its class and syntactically similar to a method. Constructor have no.
1 Ugly Realities The Dark Side of C++ Chapter 12.
Java Basics Regular Expressions.  A regular expression (RE) is a pattern used to search through text.  It either matches the.
Building Web Applications with Microsoft ASP
Lambda Expressions Version 1.1
C# - OOP TTU IT College , Autumn SEMESTER Andres käver.
Delegates and Events Svetlin Nakov Telerik Corporation
9.1 Class (static) Variables and Methods
Delegates and Events 14: Delegates and Events
FIGURE 4-10 Function Return Statements
Advanced .NET Programming I 4th Lecture
Method.
Delegates/ Anders Børjesson
CompSci 230 Software Construction
.NET and .NET Core: Languages, Cloud, Mobile and AI
REBOL Writing Functions.
Starting Out with Java: From Control Structures through Objects
6 Delegate and Lambda Expressions
Overloading and Overriding
Functions.
CS2011 Introduction to Programming I Methods (I)
METHODS, CLASSES, AND OBJECTS A FIRST LOOK
TTU IT College 2018/2019, Andres käver
Function Defaults C++ permits functions to be declared with default values for some, or all, of its parameters Allows for the function to be called without.
CIS 199 Final Review.
Advanced .NET Programming I 4th Lecture
Corresponds with Chapter 5
Chengyu Sun California State University, Los Angeles
Presentation transcript:

IT College 2016, Andres käver http://enos.itcollege.ee/~akaver/csharp C# - DELEGATES IT College 2016, Andres käver http://enos.itcollege.ee/~akaver/csharp

C# - Delegates A delegate is a type that defines a method signature, and can provide a reference to any method with a compatible signature. You can invoke (or call) the method through the delegate. Delegates are used to pass methods as arguments to other methods.

C# - Delegates Basic usage public delegate void SampleDelegate(string str); class SampleClassDelegate { // Method that matches the SampleDelegate signature. public static void SampleMethod(string message) // Add code here. } // Method that instantiates the delegate. void SampleDelegate() SampleDelegate sd = SampleMethod; sd("Sample string");

C# - Delegates Declare delegate signature (new type) delegate returntype DelegateMethod(arguments….) Declare delegate variable, assign suitable method to it DelegateMethod methodCall = SomeSuitableMehtod; Use methodCall in your code methodCall(parameters…)

C# - Func<…>, Action<…> Func<parameterTypes0..32,TResult> To simplify code, don’t declare explicit new delegate – use Func Func<bool> methodCall = someMethodNoArguments; Func<int,bool> methodCall = someMehtodWithIntParameter; When method returns void, use Action<parameterTypes0..32>

C# - Delegates, Anonymous methods You can use anonymous method with delegates Func<bool> methodCall = delegate() { return someMethod(); }; Func<int, bool> methodCall = delegate(int x) { return someMethod(x); };

C# - delegates, lambda expression You can assign lambda expression to Func Func<bool> methodCall = () => SomeMehtod(); Func<int, bool> methodCall = (x) => SomeMethod(x);