Lambda Expressions By Val Feldsher.

Slides:



Advertisements
Similar presentations
Lambda Expressions Matt Van Horn Software Engineer Iverson Gaming Systems, Inc.
Advertisements

Introduction to C Programming
CPSC 388 – Compiler Design and Construction
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Svetlin Nakov Telerik Corporation
.NET 3.5 – Mysteries. NetFx Evolution NetFx 1.0 C# 1.0, VB 7.0, VS.NET NetFx 1.1 C# 1.1, VB 7.1, VS 2003 NetFx 2.0 C# 2.0, VB 8.0, VS 2005 NetFx 3.0 C#
Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type.
Objectives In this chapter, you will:
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
1 Chapter 7 User-Defined Methods Java Programming from Thomson Course Tech, adopted by kcluk.
Introduction to Programming with Java, for Beginners Scope.
PARALLEL PROGRAMMING ABSTRACTIONS 6/16/2010 Parallel Programming Abstractions 1.
Programming Languages
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Based on material from Telerik Corporation.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
Lambda Expressions Version 1.0
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
User Defined Methods Methods are used to divide complicated programs into manageable pieces. There are predefined methods (methods that are already provided.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
IAP C# 2011 Lecture 2: Delegates, Lambdas, LINQ Geza Kovacs.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
LINQ and Lambda Expressions Telerik Software Academy LINQ Overview.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 8: Namespaces, the class string, and User-Defined Simple Data Types.
Lambda Expressions Version 1.1
Arithmetic Expressions Function Calls Output
Principles of programming languages 12: Functional programming
Chapter 7 User-Defined Methods.
Names and Attributes Names are a key programming language feature
Introduction to LINQ and Generic Collections
Objectives In this chapter, you will:
Enumeration Type Data type: a set of values with a set of operations on them Enumeration type: a simple data type created by the programmer To define an.
Introduction to Parsing (adapted from CS 164 at Berkeley)
MIS Professor Sandvig MIS 324 Professor Sandvig
Programming with ANSI C ++
Section 3.7 Implicit Functions
Methods Attributes Method Modifiers ‘static’
Upgrading Your C# Programming Skills to Be a More Effective Developer
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Iterative Constructs Review
Advanced .NET Programming I 4th Lecture
Ch. 4 – Semantic Analysis Errors can arise in syntax, static semantics, dynamic semantics Some PL features are impossible or infeasible to specify in grammar.
Haskell.
CS 2304 Function Pointers & Lambda Functions
JavaScript Syntax and Semantics
Delegates/ Anders Børjesson
Functional Programming with Java
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
.NET and .NET Core 9. Towards Higher Order Pan Wuming 2017.
Array Data Structure Chapter 6
6 Delegate and Lambda Expressions
Array Data Structure B.Ramamurthy 11/21/2018 B.Ramamurthy.
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
Introduction to LINQ Chapter 11 10/28/2015 Lect 4 CT1411.
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Introduction to Classes and Objects
Introduction to LINQ Chapter 11.
CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics
Functional interface.
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
7 Arrays.
Methods.
Array Data Structure Chapter 6
Objectives In this chapter, you will:
LINQ - 2 Ravi Kumar C++/C# Team.
Recursive Procedures and Scopes
Chapter 15 Event-Driven Programming and Animations Part 2
Advanced .NET Programming I 5th Lecture
„Lambda expressions, Optional”
Advanced .NET Programming I 4th Lecture
Programming Fundamental-1
Presentation transcript:

Lambda Expressions By Val Feldsher

Used to create delegates or expression tree types Overview Anonymous function Lambda Expressions Expression Lambda Statement Lambda Used to create delegates or expression tree types May or may not have parameters Implicit Explicit Operator => (goes to) (input parameter) => statement/expression

Lambdas are less verbose than anonymous methods Anonymous: Lambda vs. Anonymous Lambdas are less verbose than anonymous methods Anonymous: Lambda

Simple expression on right hand side x => 2 * x (x, y) => x + y Expression Lambdas Simple expression on right hand side x => 2 * x Simple expression, no brackets necessary (x, y) => x + y Need prentices if specifying more than one parameter. (int x, string y) => y.Length > x Sometimes types need to be specified explicitly because they can’t be inferred. () => MyFunction() No parameters

Lambdas can contain multi-line statements on the right hand side Statement Lambdas Lambdas can contain multi-line statements on the right hand side

Standard Query Operators Many standard query operators (LINQ) take a generic delegate of type Func<T, Tresult> as a parameter.

Type can be inferred from: Type Inference Type can be inferred from: Underlying delegate Type of elements in source sequence(LINQ) General rules: Must contain same number of parameters as delegate Each input in lambda must be implicitly convertible to delegate parameter types Return type in lambda must be implicitly convertible to delegate return type

Variables declared in lambda are not accessible in enclosing method. Variable Scope Lambda can capture a variable or a parameter that is defined in enclosing method (unless it’s a ref or out parameter). Variables declared in lambda are not accessible in enclosing method. Return statement in lambda does not cause enclosing method to return.

Lambda Expression Trees Similar to expression lambdas but are not treated as delegates but rather as “data” – abstract syntax tree (AST) Has to be compiled before can be executed as delegate Can manipulate tree data at run time and compile to executable

Questions?